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
Select Git revision
  • 20-cover-in-regression-testing-usage-of-new-transactionbuilder-properties-features-specific-to
  • 21-review-list-of-exposed-core-c-functions-in-wax-and-follow-it-in-wasm-representation
  • as-extended_variant_creator_functor-update
  • authority-tracing-hived-bump
  • bw_add_error_cause
  • bw_asset_formatters
  • bw_doc_update
  • bw_emscripten_base_class_rebase
  • bw_emscripten_base_class_simple_rebase
  • bw_fix_account_validation
  • bw_hive_apps_custom_operations
  • bw_html_verify_authority
  • bw_oneof_unions
  • bw_parse_proto_extensions_fix
  • bw_perf_test
  • bw_std_set_binding
  • bw_test_env_enh_proposal
  • bw_tm-add-other-extensions
  • bw_tm-bump-hive-submodule
  • bw_tm-expose-suggest-brain-key
  • bw_tm-hc-improvements
  • bw_tm-improve-formatting-custom-jsons
  • bw_u23_10_ci_base_image
  • develop
  • docs
  • fw-add-global-playwright-hooks
  • fw-add-matrix-to-ci
  • fw-add-test-for-transforming-post-transaction-to-legacy-format
  • fw-add-tests-for-comment-operation-factory
  • fw-extend_tests_enviroment
  • jl-healthchecker-component
  • jziebinski/ast-api-client-generator
  • jziebinski/ci-config
  • jziebinski/fix-failing-pre-commit
  • jziebinski/fix-impacted-accounts-functions
  • jziebinski/test-structure
  • jziebinski/wax-ci-static-code-analysis
  • kmochocki/jziebinski/itransaction
  • kmochocki/mt-remove-notifications
  • lucius_bump_trace_hived
  • lucius_bump_trace_hived_2
  • lucius_bump_trace_hived_3
  • marek/6-add-function-to-deserialize-transaction-binary-json
  • marek/collect_signing_keys
  • marek/collect_signing_keys_struct_v2
  • marek/new-methods
  • marek/std_function-research
  • marek/tm-implement-formatters
  • marek/wasm-size
  • master
  • merged-proto-protocol
  • mk-tm-proto-protocol
  • msobczyk/serialize-witness-properties-python
  • msobczyk/serialize-witness-set-properties-python
  • origin/rm-msgspec-refactor
  • rm-bw_expose_key_utility_functions
  • rm-msgspec-refactor_helpy_removed
  • rm-prepare-tests
  • tm-bw_fix_account_validation
  • tm-encryption-extension-wip
  • tm-remove-tail-npm-pack-package
  • tm-use-more-wasm
  • tm-wasm-throws-tests
  • tm-wax-encrypt-buffer-backup
  • unique-id-assertion
  • wk-python-proto
  • wk_ci_base_image_supplement
  • wkedzierski/bump-hive
  • wkedzierski/calculate_current_inflation_rate
  • 1.27.6-rc0
  • 1.27.6-rc1
  • 1.27.6-rc2
  • 1.27.6-rc3
  • 1.27.6-rc4
  • 1.27.6-rc5
  • 1.27.6-rc6
  • 1.27.6-rc7
  • v0.0.1a0
  • v0.0.1a1
  • v0.0.1a2
  • v0.0.1a3
  • v0.0.1a4
  • v0.0.1a5
  • v0.0.2a0
  • v0.0.2a1
  • v0.0.2a2
  • v0.0.2a3
  • v0.0.2a4
  • v0.0.3a0
  • v0.0.3a1
  • v0.3.8a1
  • v0.3.9
92 results

Target

Select target project
  • hive/wax
1 result
Select Git revision
  • 20-cover-in-regression-testing-usage-of-new-transactionbuilder-properties-features-specific-to
  • 21-review-list-of-exposed-core-c-functions-in-wax-and-follow-it-in-wasm-representation
  • as-extended_variant_creator_functor-update
  • authority-tracing-hived-bump
  • bw_add_error_cause
  • bw_asset_formatters
  • bw_doc_update
  • bw_emscripten_base_class_rebase
  • bw_emscripten_base_class_simple_rebase
  • bw_fix_account_validation
  • bw_hive_apps_custom_operations
  • bw_html_verify_authority
  • bw_oneof_unions
  • bw_parse_proto_extensions_fix
  • bw_perf_test
  • bw_std_set_binding
  • bw_test_env_enh_proposal
  • bw_tm-add-other-extensions
  • bw_tm-bump-hive-submodule
  • bw_tm-expose-suggest-brain-key
  • bw_tm-hc-improvements
  • bw_tm-improve-formatting-custom-jsons
  • bw_u23_10_ci_base_image
  • develop
  • docs
  • fw-add-global-playwright-hooks
  • fw-add-matrix-to-ci
  • fw-add-test-for-transforming-post-transaction-to-legacy-format
  • fw-add-tests-for-comment-operation-factory
  • fw-extend_tests_enviroment
  • jl-healthchecker-component
  • jziebinski/ast-api-client-generator
  • jziebinski/ci-config
  • jziebinski/fix-failing-pre-commit
  • jziebinski/fix-impacted-accounts-functions
  • jziebinski/test-structure
  • jziebinski/wax-ci-static-code-analysis
  • kmochocki/jziebinski/itransaction
  • kmochocki/mt-remove-notifications
  • lucius_bump_trace_hived
  • lucius_bump_trace_hived_2
  • lucius_bump_trace_hived_3
  • marek/6-add-function-to-deserialize-transaction-binary-json
  • marek/collect_signing_keys
  • marek/collect_signing_keys_struct_v2
  • marek/new-methods
  • marek/std_function-research
  • marek/tm-implement-formatters
  • marek/wasm-size
  • master
  • merged-proto-protocol
  • mk-tm-proto-protocol
  • msobczyk/serialize-witness-properties-python
  • msobczyk/serialize-witness-set-properties-python
  • origin/rm-msgspec-refactor
  • rm-bw_expose_key_utility_functions
  • rm-msgspec-refactor_helpy_removed
  • rm-prepare-tests
  • tm-bw_fix_account_validation
  • tm-encryption-extension-wip
  • tm-remove-tail-npm-pack-package
  • tm-use-more-wasm
  • tm-wasm-throws-tests
  • tm-wax-encrypt-buffer-backup
  • unique-id-assertion
  • wk-python-proto
  • wk_ci_base_image_supplement
  • wkedzierski/bump-hive
  • wkedzierski/calculate_current_inflation_rate
  • 1.27.6-rc0
  • 1.27.6-rc1
  • 1.27.6-rc2
  • 1.27.6-rc3
  • 1.27.6-rc4
  • 1.27.6-rc5
  • 1.27.6-rc6
  • 1.27.6-rc7
  • v0.0.1a0
  • v0.0.1a1
  • v0.0.1a2
  • v0.0.1a3
  • v0.0.1a4
  • v0.0.1a5
  • v0.0.2a0
  • v0.0.2a1
  • v0.0.2a2
  • v0.0.2a3
  • v0.0.2a4
  • v0.0.3a0
  • v0.0.3a1
  • v0.3.8a1
  • v0.3.9
92 results
Show changes
Commits on Source (3)
Showing
with 242 additions and 215 deletions
import type { IEncryptingTransaction, transaction } from '../../dist/bundle';
import type { IEncryptingTransaction, ITransaction, transaction } from '../../dist/bundle';
import { createHiveChain } from '../../dist/bundle/node.js';
import { TPublicKey } from '@hiveio/beekeeper';
import "./globals.js";
......@@ -8,7 +8,7 @@ const chain = await createHiveChain();
export const utilFunctionTest = async (
{ beekeeper, chain, wax }: Pick<IWaxGlobals, 'beekeeper' | 'chain' | 'wax'>,
txOperationsLambda: (tx: IEncryptingTransaction, encryptionKeys: [TPublicKey] | [TPublicKey, TPublicKey]) => void,
txOperationsLambda: (tx: ITransaction & IEncryptingTransaction<ITransaction>, encryptionKeys: [TPublicKey] | [TPublicKey, TPublicKey]) => void,
nonEncryptedOperationIndices: number[] = [],
otherEncryptionKey: boolean = false
): Promise<transaction> => {
......
......@@ -2,8 +2,6 @@ import { expect } from '@playwright/test';
import { test } from '../assets/jest-helper';
import type { IEncryptingTransaction } from '../../dist/bundle';
import {
utilFunctionTest,
commentOp,
......@@ -19,7 +17,7 @@ import {
test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with comment operation', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, commentOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(commentOp);
});
}, utilFunctionTest, commentOp);
......@@ -29,7 +27,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with transfer operation', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, transferOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(transferOp);
});
}, utilFunctionTest, transferOp);
......@@ -39,7 +37,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with custom json operation', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, customJsonOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(customJsonOp);
});
}, utilFunctionTest, customJsonOp);
......@@ -49,7 +47,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with transfer to savings operation', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, transferToSavingsOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(transferToSavingsOp);
});
}, utilFunctionTest, transferToSavingsOp);
......@@ -59,7 +57,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with transfer from savings operation', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, transferFromSavingsOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(transferFromSavingsOp);
});
}, utilFunctionTest, transferFromSavingsOp);
......@@ -69,7 +67,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with recurrent transfer operation', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, recurrentTransferOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(recurrentTransferOp);
});
}, utilFunctionTest, recurrentTransferOp);
......@@ -79,7 +77,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with different operations', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, recurrentTransferOp, convertOp, transferToSavingsOp, voteOp, commentOp, transferOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(recurrentTransferOp).pushOperation(convertOp).pushOperation(transferToSavingsOp).pushOperation(voteOp).pushOperation(commentOp).pushOperation(transferOp);
}, [1, 3]);
}, utilFunctionTest, recurrentTransferOp, convertOp, transferToSavingsOp, voteOp, commentOp, transferOp);
......@@ -89,7 +87,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with comment operation with different keys', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, commentOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(commentOp);
}, [], true);
}, utilFunctionTest, commentOp);
......@@ -99,7 +97,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with recurrent transfer operation with different keys', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, recurrentTransferOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(recurrentTransferOp);
}, [], true);
}, utilFunctionTest, recurrentTransferOp);
......@@ -109,7 +107,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with transfer to savings operation with different keys', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, transferToSavingsOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction) => {
return await utilFunctionTest(globals, tx => {
tx.pushOperation(transferToSavingsOp);
}, [], true);
}, utilFunctionTest, transferToSavingsOp);
......@@ -119,7 +117,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt transaction with different operations with different keys', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, recurrentTransferOp, convertOp, transferToSavingsOp, voteOp, commentOp, transferOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction, encryptionKeys) => {
return await utilFunctionTest(globals, (tx, encryptionKeys) => {
tx
.pushOperation(recurrentTransferOp)
.stopEncrypt()
......@@ -139,7 +137,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt some specific operations in transaction', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, recurrentTransferOp, convertOp, transferToSavingsOp, voteOp, commentOp, transferOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction, encryptionKeys) => {
return await utilFunctionTest(globals, (tx, encryptionKeys) => {
tx
.pushOperation(recurrentTransferOp)
.stopEncrypt()
......@@ -160,7 +158,7 @@ test.describe('Wax encrypted operations tests', () => {
test('Should be able to encrypt some specific operations in transaction with a barren keys pair at the end', async ({ waxTest }) => {
const retVal = await waxTest(async (globals, utilFunctionTest, recurrentTransferOp, convertOp, transferToSavingsOp, voteOp, commentOp, transferOp) => {
return await utilFunctionTest(globals, (tx: IEncryptingTransaction, encryptionKeys) => {
return await utilFunctionTest(globals, (tx, encryptionKeys) => {
tx
.pushOperation(recurrentTransferOp)
.stopEncrypt()
......
import type { TPublicKey } from "@hiveio/beekeeper";
import { IsString, Validate } from "class-validator";
import { IsPublicKey } from "../../decorators/is_public_key.js";
import type { TPublicKey } from "../../interfaces";
export class GetKeyReferencesRequest {
@Validate(IsPublicKey, { each: true })
......
import type { TPublicKey } from "@hiveio/beekeeper";
import { Type } from "class-transformer";
import { IsArray, IsBoolean, IsDateString, IsNumber, IsNumberString, IsString, Validate, ValidateNested } from "class-validator";
......@@ -6,6 +5,7 @@ import { NaiAsset } from "./asset.js";
import { IsNumberOrStringNumber } from "../../decorators/is_number_or_number_string.js";
import { IsPublicKey } from "../../decorators/is_public_key.js";
import { IsAuth } from "../../decorators/is_auth.js";
import type { TPublicKey } from "../../interfaces";
export class ApiAccountAuth {
@IsString()
......
import { IsDateString, IsNumber, IsString, Validate } from "class-validator";
import { IsPublicKey } from "../../decorators/is_public_key";
import { TPublicKey } from "@hiveio/beekeeper";
import type { TPublicKey } from "../../interfaces";
export class ApiWitness {
@IsNumber()
......
import type { IBeekeeperUnlockedWallet, TPublicKey } from "@hiveio/beekeeper";
import type { IBinaryViewArrayNode, IBinaryViewNode, IBinaryViewOutputData, IBrainKeyData, IHiveAssetData, IManabarData, IPrivateKeyData, ITransaction, IWaxBaseInterface, TBlockHash, THexString, TNaiAssetConvertible, TNaiAssetSource, TTimestamp } from "./interfaces";
import type { IBinaryViewArrayNode, IBinaryViewNode, IBinaryViewOutputData, IBrainKeyData, IHiveAssetData, IManabarData, IPrivateKeyData, ITransaction, IWaxBaseInterface, TBlockHash, THexString, TNaiAssetConvertible, TNaiAssetSource, TPublicKey, TTimestamp } from "./interfaces";
import type { binary_data_node, json_price, MainModule, proto_protocol, protocol, result, VectorBinaryDataNode, VectorString, witness_set_properties_data, wax_authorities } from "../build_wasm/wax.common";
import type { IChainConfig } from "../build_wasm/config";
import type { ApiOperation, NaiAsset } from "./api";
......@@ -22,6 +20,7 @@ import { plainToInstance } from "class-transformer";
import { validateSync } from "class-validator";
import type { AccountAuthorityUpdateOperation } from "./complex_operations"; // only for TypeDoc purposes :-(
import { ISignatureProvider } from "./extensions/signatures";
const PERCENT_VALUE_DOUBLE_PRECISION = 100;
export const ONE_HUNDRED_PERCENT = 100 * PERCENT_VALUE_DOUBLE_PRECISION;
......@@ -358,7 +357,7 @@ export class WaxBaseApi implements IWaxBaseInterface {
return this.extract(publicKey);
}
public encrypt(wallet: IBeekeeperUnlockedWallet, content: string, mainEncryptionKey: TPublicKey, otherEncryptionKey?: TPublicKey, nonce?: number): string {
public encrypt(wallet: ISignatureProvider, content: string, mainEncryptionKey: TPublicKey, otherEncryptionKey?: TPublicKey, nonce?: number): string {
const encrypted = wallet.encryptData(content, mainEncryptionKey, otherEncryptionKey, nonce);
return safeWasmCall(() => this.proto.cpp_crypto_memo_dump_string({
......@@ -388,7 +387,7 @@ export class WaxBaseApi implements IWaxBaseInterface {
return this.cachedConfig;
}
public decrypt(wallet: IBeekeeperUnlockedWallet, encrypted: string): string {
public decrypt(wallet: ISignatureProvider, encrypted: string): string {
const data = safeWasmCall(() => this.proto.cpp_crypto_memo_from_string(encrypted));
return wallet.decryptData(data.content as string, data.from as string, data.to as string);
......
import type { IBeekeeperUnlockedWallet } from "@hiveio/beekeeper";
import type { IHiveChainInterface, IManabarData, ITransaction, IOnlineTransaction, TTimestamp, TPublicKey, TWaxExtended, TBlockHash, TWaxRestExtended, TDeepWaxApiRequestPartial } from "./interfaces";
import type { MainModule, MapStringUInt16, wax_authority, wax_authorities } from "../build_wasm/wax.common";
import { ApiAuthority, ApiWitness, BroadcastTransactionRequest, type ApiAccount, type ApiManabar, type ApiTransaction, type RcAccount } from "./api";
......@@ -15,6 +14,7 @@ import Long from "long";
import { ApiCaller, TRequestInterceptor, TResponseInterceptor } from "./util/api_caller";
import { TAccountName } from "./hive_apps_operations";
import { ISignatureProvider } from "./extensions/signatures";
export enum EManabarType {
UPVOTE = 0,
......@@ -258,7 +258,7 @@ export class HiveChainApi extends WaxBaseApi implements IHiveChainInterface {
return retVal;
}
public async encryptForAccounts(wallet: IBeekeeperUnlockedWallet, content: string, fromAccount: string, toAccount: string): Promise<string> {
public async encryptForAccounts(wallet: ISignatureProvider, content: string, fromAccount: string, toAccount: string): Promise<string> {
let from: string, to: string;
([ { memo_key: from }, { memo_key: to } ] = await this.findAccounts(...[... new Set([ fromAccount, toAccount ])]));
......
import type { TPublicKey } from "@hiveio/beekeeper";
import { authority } from "../../../../protocol.js";
import { TAccountName } from "../../../../hive_apps_operations/index.js";
import { WaxError } from "../../../../errors.js";
import { LevelBase } from "../../level_base.js";
import type { TPublicKey } from "../../../../interfaces";
export class HiveRoleAuthorityDefinition<TRole extends string> extends LevelBase<TRole> {
public constructor(
......
import type { TPublicKey } from "@hiveio/beekeeper";
import { WaxError } from "../../../../errors.js";
import { LevelBase } from "../../level_base.js";
import type { TPublicKey } from "../../../../interfaces";
export class HiveRoleMemoKeyDefinition extends LevelBase<"memo"> {
public constructor() {
......
import { asset, operation, witness_set_properties } from "../protocol.js";
import { OperationBase, IOperationSink } from "../operation_base.js";
import { type witness_set_properties_data } from "../../build_wasm/wax.common.js";
import { type TPublicKey } from "@hiveio/beekeeper";
import { EAssetName, type WaxBaseApi } from '../base_api.js';
import type Long from "long";
import { TAccountName } from "../hive_apps_operations/index.js";
import type { TPublicKey } from "../interfaces";
type TInternalAsset = asset | Long | string | BigInt | number;
......
import type { TPublicKey, TSignature, THexString, ITransaction } from "../../interfaces";
export interface ISignatureProvider {
/**
* Signs a transaction by signing a digest of the transaction
*
* @param {TPublicKey} publicKey public key in WIF format to match the private key in the underlying container. It will be used to sign the provided data
* @param {THexString} sigDigest digest of a transaction in hex format
*
* @returns {TSignature} signed data in hex format
*/
signDigest(publicKey: TPublicKey, sigDigest: THexString): TSignature;
/**
* Encrypts given data for a specific entity and returns the encrypted message
*
* @param {string} content Content to be encrypted
* @param {TPublicKey} key public key to find the private key in the underlying container and encrypt the data
* @param {?TPublicKey} anotherKey other public key to find the private key in the underlying container and encrypt the data (optional - use if the message is to encrypt for somebody else)
* @param {?number} nonce optional nonce to be explicitly specified for encryption
*
* @returns {string} base58 encrypted buffer
*/
encryptData(content: string, key: TPublicKey, anotherKey?: TPublicKey, nonce?: number): string;
/**
* Decrypts given data from a specific entity and returns the decrypted message
*
* @param {string} content Base58 content to be decrypted
* @param {TPublicKey} key public key to find the private key in the underlying container and decrypt the data
* @param {?TPublicKey} anotherKey other public key to find the private key in the underlying container and decrypt the data (optional - use if the message was encrypted for somebody else)
*
* @returns {string} decrypted buffer
*/
decryptData(content: string, key: TPublicKey, anotherKey?: TPublicKey): string;
};
export interface IOnlineSignatureProvider {
/**
* Signs a transaction by signing a digest of the transaction
*
* @param {ITransaction} transaction transaction to be signed
*
* @returns {Promise<void>} signed data in hex format
*/
signTransaction(transaction: ITransaction): Promise<void>;
};
......@@ -16,6 +16,7 @@ export { TTransactionRequiredAuthorities } from './transaction.js';
export { DEFAULT_WAX_OPTIONS_CHAIN, createHiveChain } from "./chain.js";
export { DEFAULT_WAX_OPTIONS, createWaxFoundation } from "./base.js";
export * from './extensions/signatures/index.js';
export * from './interfaces.js';
// Protobuf definitions
......
import type { IBeekeeperUnlockedWallet, TPublicKey } from "@hiveio/beekeeper";
export type { TPublicKey } from "@hiveio/beekeeper";
import type { TPublicKey } from "@hiveio/beekeeper";
export type { TPublicKey, TSignature } from "@hiveio/beekeeper";
// @ts-expect-error ts(6133) Type WaxError is used in JSDoc
import type { WaxError } from "./errors";
......@@ -15,6 +15,7 @@ import type { OperationBase } from "./operation_base";
import type { BlogPostOperation, AccountAuthorityUpdateOperation, ReplyOperation, DefineRecurrentTransferOperation, RecurrentTransferRemovalOperation, UpdateProposalOperation, WitnessSetPropertiesOperation } from "./complex_operations";
import type { ResourceCreditsOperation, CommunityOperation, FollowOperation, TAccountName } from './hive_apps_operations';
import type { IChainConfig } from "../build_wasm/config";
import { ISignatureProvider, IOnlineSignatureProvider } from "./extensions/signatures";
import type { IVerifyAuthorityTrace } from "./verify_authority_trace_interface";
export * from "./verify_authority_trace_interface";
......@@ -131,7 +132,7 @@ export interface IWaxOptionsChain extends IWaxOptions {
restApiEndpoint: string;
}
interface ITransactionBase {
export interface ITransactionBase {
/**
* Generates digest of the transaction for signing (HF26 serialization form is used).
......@@ -207,13 +208,13 @@ interface ITransactionBase {
/**
* Decrypts all underlying encrypted operations
*
* @param {IBeekeeperUnlockedWallet} wallet unlocked wallet to be used for decryption
* @param {ISignatureProvider} wallet unlocked wallet to be used for decryption
*
* @returns {transaction} protobuf transaction object
*
* @throws {WaxError} on any Wax API-related error including validation error
*/
decrypt(wallet: IBeekeeperUnlockedWallet): transaction;
decrypt(wallet: ISignatureProvider): transaction;
/**
* Returns required authority accounts from the transaction
......@@ -240,30 +241,6 @@ interface ITransactionBase {
*/
toString(): string;
/**
* Signs the transaction using given public key. Applies the transaction expiration time
*
* Encrypts operations if any were created using {@link IEncryptingTransaction} interface
*
* @param {IBeekeeperUnlockedWallet} wallet unlocked wallet to be used for signing
* @param {TPublicKey} publicKey publicKey for signing (should be available in the wallet)
*
* @returns {THexString} transaction signature signed using given key
*
* @throws {WaxError} on any Wax API-related error or no public key found in the unlocked wallet or wallet is locked
*/
sign(wallet: IBeekeeperUnlockedWallet, publicKey: TPublicKey): THexString;
/**
* Adds your signature to the internal signatures array inside underlying transaction.
*
* @param {THexString} signature signature to add
*
* @returns {THexString} added transaction signature
*
*/
sign(signature: THexString): THexString;
/**
* Checks if underlying transaction has been already signed at least one time (after {@link sign})
*
......@@ -311,6 +288,19 @@ interface ITransactionBase {
*/
toApiJson(): ApiTransaction;
/**
* Starts encryption chain
*
* Remember that in order to encrypt operations with given {@link mainEncryptionKey} and optional {@link otherEncryptionKey}
* you have to import those keys into the wallet passed to the {@link ITransactionBase.sign} method
*
* @param {TPublicKey} mainEncryptionKey First key to encrypt operations
* @param {?TPublicKey} otherEncryptionKey Optional second key to encrypt operations
*
* @returns {this & IEncryptingTransaction<this>} current transaction instance
*/
startEncrypt(mainEncryptionKey: TPublicKey, otherEncryptionKey?: TPublicKey): this & IEncryptingTransaction<this>;
/**
* Converts the created transaction into the Hive API-legacy form JSON string.
*
......@@ -336,34 +326,7 @@ interface ITransactionBase {
* Allows to serialize underlying transaction to HF26 specific binary form, then return it as hexstring.
*/
toBinaryForm(): THexString;
}
/**
* Transaction allows you to push simple operations (as inline objects)
* or use dedicated operation factories
* (to create more complex operations or multiple blockchain transactions for specific scenarios)
* into underlying transaction.
* Furthermore, it allows to perform analysis of the transaction
* by examining its id (hash),
* evaluating the digest to calculate signatures
* or extracting public keys involved in the attached signatures.
*
* Example usage:
* @example Base transaction usage
* ```typescript
* const tx = new waxFoundation.Transaction();
*
* tx.pushOperation({
* vote: {
* voter: "otom",
* author: "c0ff33a",
* permlink: "ewxhnjbj",
* weight: 2200
* }
* });
* ```
*/
export interface ITransaction extends ITransactionBase {
/**
* Pushes given operation to the operations array in the transaction
* This can also add **multiple** operations to the transaction using a straightforward complex operation interface.
......@@ -409,24 +372,62 @@ export interface ITransaction extends ITransactionBase {
* }));
* ```
*
* @returns {ITransaction} current transaction instance
* @returns {this} current transaction instance
*
* @throws {WaxError} on any Wax API-related error
*/
pushOperation(op: operation | OperationBase): ITransaction;
pushOperation(op: operation | OperationBase): this;
}
/**
* Transaction allows you to push simple operations (as inline objects)
* or use dedicated operation factories
* (to create more complex operations or multiple blockchain transactions for specific scenarios)
* into underlying transaction.
* Furthermore, it allows to perform analysis of the transaction
* by examining its id (hash),
* evaluating the digest to calculate signatures
* or extracting public keys involved in the attached signatures.
*
* Example usage:
* @example Base transaction usage
* ```typescript
* const tx = new waxFoundation.Transaction();
*
* tx.pushOperation({
* vote: {
* voter: "otom",
* author: "c0ff33a",
* permlink: "ewxhnjbj",
* weight: 2200
* }
* });
* ```
*/
export interface ITransaction extends ITransactionBase {
/**
* Starts encryption chain
* Signs the transaction using given public key. Applies the transaction expiration time
*
* Remember that in order to encrypt operations with given {@link mainEncryptionKey} and optional {@link otherEncryptionKey}
* you have to import those keys into the wallet passed to the {@link ITransactionBase.sign} method
* Encrypts operations if any were created using {@link IEncryptingTransaction} interface
*
* @param {TPublicKey} mainEncryptionKey First key to encrypt operations
* @param {?TPublicKey} otherEncryptionKey Optional second key to encrypt operations
* @param {ISignatureProvider} wallet unlocked wallet to be used for signing
* @param {TPublicKey} publicKey publicKey for signing (should be available in the wallet)
*
* @returns {THexString} transaction signature signed using given key
*
* @returns {IEncryptingTransaction} current transaction instance
* @throws {WaxError} on any Wax API-related error or no public key found in the unlocked wallet or wallet is locked
*/
startEncrypt(mainEncryptionKey: TPublicKey, otherEncryptionKey?: TPublicKey): IEncryptingTransaction;
sign(wallet: ISignatureProvider, publicKey: TPublicKey): THexString;
/**
* Adds your signature to the internal signatures array inside underlying transaction.
*
* @param {THexString} signature signature to add
*
* @returns {THexString} added transaction signature
*
*/
sign(signature: THexString): THexString;
}
/**
......@@ -456,73 +457,22 @@ export interface ITransaction extends ITransactionBase {
* }).stopEncrypt();
* ```
*/
export interface IEncryptingTransaction extends ITransactionBase {
/**
* Pushes given operation to the operations array in the transaction
* This can also add **multiple** operations to the transaction using a straightforward complex operation interface.
*
* We provide a standard set of factories with our implementation, but you can also create custom factories by extending the {@link OperationBase} class.
*
* @param {operation | OperationBase} op operation to append to the transaction (can be hive apps operation)
* or Class instance for a complex operation that will produce operations including given params
*
* @see Complex operations:
* {@link AccountAuthorityUpdateOperation} Creates an account authority update operation
* {@link BlogPostOperation} Creates a blog post. It requires the category on blog post to be set,
* {@link ReplyOperation} Creates a reply to a comment or a blog post. It requiers parent author and parent permlink to be set,
* {@link DefineRecurrentTransferOperation} Creates or updates a recurrent transfer. It requires the amount to be set and to be non-zero, otherwise the removal will be generated automatically,
* {@link RecurrentTransferRemovalOperation} Creates an operation removing existing recurrent transfer
* {@link UpdateProposalOperation} Creates an update proposal operation. You can optionally set the end date of the proposal,
* {@link WitnessSetPropertiesOperation} Creates a witness set properties operation with automatic data serialization,
*
* @see Hive Apps operations:
* {@link CommunityOperation} Allows to manipulate the community options,
* {@link FollowOperation} Allows to manipulate the follow options,
* {@link ResourceCreditsOperation} Allows to delegate or remove delegation of resource credits to given account(s),
*
* @example Building blog post
* ```typescript
* tx.pushOperation(new BlogPostOperation({
* category: "test-category",
* author: "gtg",
* title: "Post with category",
* body: "Post with category",
* permlink: "post-with-category",
* tags: ["spam"],
* description: "Post with category"
* }));
* ```
*
* @example Building recurrent transfer with pair id and automaically generated removal
* ```typescript
* tx.pushOperation(new DefineRecurrentTransferOperation({
* from: "initminer",
* to: "gtg",
* pairId: 100
* }));
* ```
*
* @returns {IEncryptingTransaction} current transaction instance
*
* @throws {WaxError} on any Wax API-related error
*/
pushOperation(op: operation | OperationBase): IEncryptingTransaction;
export interface IEncryptingTransaction<StopEncryptResult extends ITransactionBase> {
/**
* Stops encryption chain
*
* Note: This call is optional if you are not going to push any other decrypted operations
*
* @returns {ITransaction} current transaction instance
* @returns {StopEncryptResult} current transaction instance
*/
stopEncrypt(): ITransaction;
stopEncrypt(): StopEncryptResult;
};
/**
* Extends {@link ITransaction} interface by functionality which requires online chain access (i.e. accessing account
* authority to prevent private keys leak).
*/
export interface IOnlineTransaction extends ITransaction {
export interface IOnlineTransaction extends ITransactionBase {
/**
* Allows to perform transaction checks which require additional access to chain APIs i.e. to retrieve account data.
*
......@@ -545,10 +495,42 @@ export interface IOnlineTransaction extends ITransaction {
*/
generateAuthorityVerificationTrace(useLegacySerialization?: boolean, externalTx?: ITransaction): Promise<IVerifyAuthorityTrace>;
/** Overrided only to change return type.
* {@inheritdoc ITransaction.pushOperation}
/**
* Signs the transaction using given public key. Applies the transaction expiration time
*
* Encrypts operations if any were created using {@link IEncryptingTransaction} interface
*
* @param {IOnlineSignatureProvider} wallet unlocked wallet to be used for signing
*
* @returns {Promise<void>} transaction signature signed using given key
*
* @throws {WaxError} on any Wax API-related error or no public key found in the unlocked wallet or wallet is locked
*/
sign(wallet: IOnlineSignatureProvider): Promise<void>;
/**
* Signs the transaction using given public key. Applies the transaction expiration time
*
* Encrypts operations if any were created using {@link IEncryptingTransaction} interface
*
* @param {ISignatureProvider} wallet unlocked wallet to be used for signing
* @param {TPublicKey} publicKey publicKey for signing (should be available in the wallet)
*
* @returns {THexString} transaction signature signed using given key
*
* @throws {WaxError} on any Wax API-related error or no public key found in the unlocked wallet or wallet is locked
*/
pushOperation(op: operation | OperationBase): IOnlineTransaction;
sign(wallet: ISignatureProvider, publicKey: TPublicKey): THexString;
/**
* Adds your signature to the internal signatures array inside underlying transaction.
*
* @param {THexString} signature signature to add
*
* @returns {THexString} added transaction signature
*
*/
sign(signature: THexString): THexString;
};
export interface IHiveAssetData {
......@@ -843,7 +825,7 @@ export interface IWaxBaseInterface {
/**
* Encrypts given data using two keys and dumps result to the encrypted string in `#encrypted` format
*
* @param {IBeekeeperUnlockedWallet} wallet Wallet with imported {@link mainEncryptionKey} and {@link otherEncryptionKey} keys
* @param {ISignatureProvider} wallet Wallet with imported {@link mainEncryptionKey} and {@link otherEncryptionKey} keys
* @param {string} content Content to be encoded
* @param {TPublicKey} mainEncryptionKey First key to encrypt operations
* @param {?TPublicKey} otherEncryptionKey Optional second key to encrypt operations
......@@ -851,17 +833,17 @@ export interface IWaxBaseInterface {
*
* @returns {string} Encrypted content
*/
encrypt(wallet: IBeekeeperUnlockedWallet, content: string, mainEncryptionKey: TPublicKey, otherEncryptionKey?: TPublicKey, nonce?: number): string;
encrypt(wallet: ISignatureProvider, content: string, mainEncryptionKey: TPublicKey, otherEncryptionKey?: TPublicKey, nonce?: number): string;
/**
* Decrypts given data from the encrypted string in `#encrypted` format
*
* @param {IBeekeeperUnlockedWallet} wallet Wallet with imported encryption keys
* @param {ISignatureProvider} wallet Wallet with imported encryption keys
* @param {string} encrypted Content to be decoded
*
* @returns {string} Decoded content
*/
decrypt(wallet: IBeekeeperUnlockedWallet, encrypted: string): string;
decrypt(wallet: ISignatureProvider, encrypted: string): string;
/**
* Calculates current manabar value for Hive account based on given arguments
......@@ -1119,14 +1101,14 @@ export interface IHiveChainInterface extends IWaxBaseInterface {
/**
* Encrypts given data using memo public keys of two accounts and dumps result to the encrypted string in `#encrypted` format
*
* @param {IBeekeeperUnlockedWallet} wallet Wallet with imported {@link fromAccount} and {@link toAccount} memo public keys
* @param {ISignatureProvider} wallet Wallet with imported {@link fromAccount} and {@link toAccount} memo public keys
* @param {string} content Content to be encoded
* @param {string} fromAccount first account to retrieve the memo public key used for encryption
* @param {?string} toAccount second account to retrieve the memo public key used for encryption
*
* @returns {Promise<string>} Encrypted content
*/
encryptForAccounts(wallet: IBeekeeperUnlockedWallet, content: string, fromAccount: string, toAccount?: string): Promise<string>;
encryptForAccounts(wallet: ISignatureProvider, content: string, fromAccount: string, toAccount?: string): Promise<string>;
/**
* Allows to override default endpoint URL used to call RPC APIs initially configured by {@link IWaxOptionsChain} passed to {@link createHiveChain} builder function.
......
import { DEFAULT_WAX_OPTIONS } from "./base";
import { HiveChainApi, TChainReferenceData } from "./chain_api";
import { OperationBase } from "./operation_base";
import { Transaction, TTransactionRequiredAuthorities } from "./transaction";
import type { authority, account_create, account_create_with_delegation, comment, create_claimed_account, recurrent_transfer, transfer, transfer_from_savings, transfer_to_savings, account_update2, account_update } from "./protocol";
import { OperationVisitor } from "./visitor";
import type { IOnlineTransaction, ITransaction, TPublicKey, TTimestamp } from "./interfaces";
import type { IOnlineTransaction, ITransaction, THexString, TPublicKey, TSignature, TTimestamp } from "./interfaces";
import { operation } from "./protocol";
import { TAccountName } from "./hive_apps_operations";
import type { IVerifyAuthorityTrace } from "./verify_authority_trace_interface";
import { AccountAuthorityCachingProvider } from "./util/account_authority_caching_provider";
import { convertAuthorityTrace } from "./verify_authority_trace";
import type { TSignature } from "@hiveio/beekeeper";
import { authority_verification_trace, MapStringUInt16, required_authority_collection, wax_authority } from "../build_wasm/wax.common";
import type { IOnlineSignatureProvider, ISignatureProvider } from "./extensions/signatures";
type TAuthorityHolder = {
owner?: authority, /// unfortunetely protobuf defs have optional values allowed on defined authority levels
......@@ -163,9 +162,14 @@ export class OnlineTransaction extends Transaction implements IOnlineTransaction
super(chain, chainReferenceData.head_block_id, expirationRefTime, expirationTime);
}
public override pushOperation(op: operation | OperationBase): OnlineTransaction {
super.pushOperation(op);
return this;
public sign(wallet: ISignatureProvider, publicKey: TPublicKey): THexString;
public sign(wallet: IOnlineSignatureProvider): Promise<void>;
public sign(signature: THexString): THexString;
public sign(walletOrSignature: IOnlineSignatureProvider | ISignatureProvider | THexString, publicKey?: TPublicKey): Promise<void> | THexString {
if (typeof walletOrSignature === "object" && "signTransaction" in walletOrSignature)
return walletOrSignature.signTransaction(this as ITransaction);
return super.sign(walletOrSignature, publicKey);
}
public async generateAuthorityVerificationTrace(useLegacySerialization: boolean = false, externalTx?: ITransaction): Promise<IVerifyAuthorityTrace> {
......
import type { IBeekeeperUnlockedWallet, TPublicKey } from "@hiveio/beekeeper";
import type { IBinaryViewNode, IBinaryViewOutputData, IEncryptingTransaction, ITransaction, TBlockHash, THexString, TTimestamp, TTransactionId } from "./interfaces";
import type { IBinaryViewNode, IBinaryViewOutputData, IEncryptingTransaction, ITransaction, TBlockHash, THexString, TPublicKey, TTimestamp, TTransactionId } from "./interfaces";
import { authority, transaction, type operation } from "./protocol.js";
import { WaxBaseApi } from "./base_api.js";
......@@ -10,6 +9,7 @@ import { WaxError } from "./errors.js";
import type { ApiTransaction } from "./api";
import { safeWasmCall } from "./util/wasm_errors";
import type { TAccountName } from "./hive_apps_operations";
import { ISignatureProvider } from "./extensions/signatures";
type TIndexBeginEncryption = {
mainEncryptionKey: TPublicKey;
......@@ -31,7 +31,7 @@ export type TTransactionRequiredAuthorities = {
other: Array<authority>;
}
export class Transaction implements ITransaction, IEncryptingTransaction {
export class Transaction implements ITransaction, IEncryptingTransaction<ITransaction> {
private target: transaction;
private taposRefer(hex: TBlockHash): { ref_block_num: number; ref_block_prefix: number } {
......@@ -152,10 +152,10 @@ export class Transaction implements ITransaction, IEncryptingTransaction {
return JSON.stringify(transaction.toJSON(this.target));
}
public startEncrypt(mainEncryptionKey: TPublicKey, otherEncryptionKey?: TPublicKey): Transaction {
public startEncrypt(mainEncryptionKey: TPublicKey, otherEncryptionKey?: TPublicKey): this & IEncryptingTransaction<this> {
this.indexKeeper.push({ mainEncryptionKey, otherEncryptionKey: otherEncryptionKey ?? mainEncryptionKey, begin: this.target.operations.length });
return this;
return this as IEncryptingTransaction<this> & this;
}
public stopEncrypt(): Transaction {
......@@ -179,7 +179,7 @@ export class Transaction implements ITransaction, IEncryptingTransaction {
return this;
}
public pushOperation(op: operation | OperationBase): Transaction {
public pushOperation(op: operation | OperationBase): this {
if ("finalize" in op) // Complex operation (to be built)
this.produceOperations(op);
else // Standard raw-object operation
......@@ -289,7 +289,7 @@ export class Transaction implements ITransaction, IEncryptingTransaction {
this.target.expiration = expiration.toISOString().slice(0, -5);
}
public decrypt(wallet: IBeekeeperUnlockedWallet): transaction {
public decrypt(wallet: ISignatureProvider): transaction {
const visitor = new EncryptionVisitor(EEncryptionType.DECRYPT, (data: string) => {
if(data.startsWith('#'))
return this.api.decrypt(wallet, data)
......@@ -303,7 +303,7 @@ export class Transaction implements ITransaction, IEncryptingTransaction {
return this.target;
}
private encryptOperations(wallet: IBeekeeperUnlockedWallet): void {
private encryptOperations(wallet: ISignatureProvider): void {
for(const index of this.indexKeeper)
for(let i = index.begin; i < (index.end ?? this.target.operations.length); ++i) {
const visitor = new EncryptionVisitor(EEncryptionType.ENCRYPT, (data: string) => {
......@@ -314,7 +314,7 @@ export class Transaction implements ITransaction, IEncryptingTransaction {
}
}
public sign(walletOrSignature: IBeekeeperUnlockedWallet | THexString, publicKey?: TPublicKey): THexString {
public sign(walletOrSignature: ISignatureProvider | THexString, publicKey?: TPublicKey): THexString {
this.validate();
if (typeof walletOrSignature === 'string') {
......
import { authority_verification_trace, path_entry, VectorPathEntry } from "../build_wasm/wax.common";
import type { IAuthorityPathEntry, IAuthorityPathTraceData, IAuthorityTraceSignatureInfo, IVerifyAuthorityTrace, TAuthorityEntryProcessingStatus } from "./verify_authority_trace_interface";
import type { TPublicKey, TSignature } from "@hiveio/beekeeper";
import type { TPublicKey, TSignature } from "./interfaces";
/// TODO export it through embind
enum authority_entry_processing_flags
......
import type { TPublicKey, TSignature } from "@hiveio/beekeeper";
import type { TPublicKey, TSignature } from './interfaces';
import type { TAccountName } from './hive_apps_operations';
export type TAuthorityRole = string; /// TODO: unify with role type defined in account authority update meta operation
......