Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: BNC 2 backport #1812

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/rpc-proxy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
- name: Set up QEMU
if: ${{ github.event_name != 'pull_request' }}
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
if: ${{ github.event_name != 'pull_request' }}
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
Expand All @@ -36,7 +36,7 @@ jobs:
uses: docker/metadata-action@v5
with:
images: vechain/sdk-rpc-proxy

- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
Expand All @@ -48,8 +48,10 @@ jobs:

- name: Create .trivyignore file
# "cross-spawn" is resolved as version 7.0.5 but Trivy keeps showing the error
run: echo "CVE-2024-21538" > .trivyignore

run: |
echo "CVE-2024-21538" > .trivyignore
echo "CVE-2024-13176" >> .trivyignore
- name: Run Trivy Scan
uses: aquasecurity/trivy-action@master
with:
Expand All @@ -64,7 +66,7 @@ jobs:
env:
# See https://github.com/aquasecurity/trivy/discussions/7538
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2

- name: Build and push
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@v6
Expand Down
2 changes: 1 addition & 1 deletion apps/sdk-cloudflare-integration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
};

// Create private key
const privateKey = await Secp256k1.generatePrivateKey();
const privateKey = Secp256k1.generatePrivateKey();

// 4 - Sign transaction
const signedTransaction = Transaction.of(body).sign(privateKey);
Expand Down
6 changes: 3 additions & 3 deletions apps/sdk-hardhat-integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ The `hardhat.config.js` is the main configuration file. By specifying the desire
Note that:

- The network name should contain `vechain`, otherwise, it may result in an error.
- In the network configuration, two additional fields can be added: `delegator` and `useDebug`. These fields allow for more customization and control over the network settings, catering to specific project requirements and preferences.
- In the network configuration, two additional fields can be added: `gasPayer` and `useDebug`. These fields allow for more customization and control over the network settings, catering to specific project requirements and preferences.
- **Debug Mode**: The `debug` field enables or disables debug mode.
- **Delegator**: The `delegator` field allows you to delegate the transaction to a delegator. It supports two optional parameters: - **Delegator**: The `delegator` field allows you to delegate the transaction to a delegator. It supports two optional parameters: `delegatorPrivateKey` and `delegatorUrl`.
- **Delegator**: The `gasPayer` field allows you to delegate the transaction to a gasPayer. It supports two optional parameters: - **Delegator**: The `gasPayer` field allows you to delegate the transaction to a gasPayer. It supports two optional parameters: `delegatorPrivateKey` and `delegatorUrl`.
- When configuring your Solidity compiler settings in hardhat.config.js, it's recommended to set the evmVersion to "Paris" for projects targeting the latest EVM functionalities. This setting ensures that the compiled bytecode is optimized for the most recent features and gas cost adjustments associated with the Paris EVM version. Using an EVM version other than "Paris" could potentially lead to issues with unsupported opcodes, especially if your contracts rely on newer EVM features introduced in or after the Paris update.

This flexibility in the configuration file allows developers to tailor their development experience and adapt it to the requirements of their projects, ensuring a smooth and efficient development process.
This flexibility in the configuration file allows developers to tailor their development experience and adapt it to the requirements of their projects, ensuring a smooth and efficient development process.
16 changes: 8 additions & 8 deletions apps/sdk-hardhat-integration/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type HttpNetworkConfig } from 'hardhat/types';
*
* They have custom parameters:
* - debug: whether to enable debug mode
* - delegator: the delegator to use
* - gasPayer: the gasPayer to use
* - enableDelegation: whether to enable fee delegation
*/
const config: HardhatUserConfig = {
Expand Down Expand Up @@ -42,7 +42,7 @@ const config: HardhatUserConfig = {
'7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158'
],
debug: false,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
Expand All @@ -65,7 +65,7 @@ const config: HardhatUserConfig = {
passphrase: 'vechainthor'
},
debug: true,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
Expand All @@ -74,7 +74,7 @@ const config: HardhatUserConfig = {
} satisfies HttpNetworkConfig,

/**
* Testnet configuration - with delegator url
* Testnet configuration - with gasPayer url
*/
vechain_testnet_delegator_url: {
// Testnet
Expand All @@ -88,7 +88,7 @@ const config: HardhatUserConfig = {
passphrase: 'vechainthor'
},
debug: true,
delegator: {
gasPayer: {
delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269'
},
enableDelegation: true,
Expand All @@ -100,7 +100,7 @@ const config: HardhatUserConfig = {
} satisfies HttpNetworkConfig,

/**
* Testnet configuration - with delegator private key
* Testnet configuration - with gasPayer private key
*/
vechain_testnet_delegator_private_key: {
// Testnet
Expand All @@ -114,7 +114,7 @@ const config: HardhatUserConfig = {
passphrase: 'vechainthor'
},
debug: true,
delegator: {
gasPayer: {
delegatorPrivateKey:
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5'
},
Expand All @@ -137,7 +137,7 @@ const config: HardhatUserConfig = {
],
debug: false,
enableDelegation: false,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
Expand Down
14 changes: 7 additions & 7 deletions docker-compose.rpc-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ services:

# Default configuration for the RPC proxy service
rpc-proxy:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
container_name: rpc-proxy
Expand All @@ -80,7 +80,7 @@ services:

# 1. Example of a custom configuration file for the RPC proxy service
rpc-proxy-custom-config-file:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -95,7 +95,7 @@ services:

# 2. Example of a custom parameters for the RPC proxy service
rpc-proxy-custom-parameters:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -110,7 +110,7 @@ services:

# 3. Example of a custom accounts for the RPC proxy service
rpc-proxy-custom-accounts:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -125,7 +125,7 @@ services:

# 3. Example of a custom mnemonic for the RPC proxy service
rpc-proxy-custom-mnemonic:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -142,7 +142,7 @@ services:

# 4. Example of a custom delegation by private key for the RPC proxy service
rpc-proxy-with-delegation-by-private-key:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand All @@ -161,7 +161,7 @@ services:

# 5. Example of a custom delegation by url for the RPC proxy service
rpc-proxy-with-delegation-by-url:
build:
build:
context: .
dockerfile: docker/rpc-proxy/Dockerfile
environment:
Expand Down
4 changes: 2 additions & 2 deletions docker/rpc-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ COPY --from=builder /app/package.json /app/package.json
WORKDIR /app
RUN yarn workspace @vechain/sdk-rpc-proxy install --production --frozen-lockfile --ignore-scripts --prefer-offline \
&& yarn cache clean \
&& adduser -D rpc-proxy-user
&& adduser -D rpc-proxy-user
# Create a new user to run the app so we do not use root
USER rpc-proxy-user

# Tell we are running with Docker
ENV RUNNING_WITH_DOCKER=true

# Set the default command to use node to run the app
CMD ["node", "packages/rpc-proxy/dist/index.js"]
CMD ["node", "packages/rpc-proxy/dist/index.js"]
5 changes: 2 additions & 3 deletions docs/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,8 @@ const thorSoloClient = ThorClient.at(THOR_SOLO_URL);
const provider = new VeChainProvider(
thorSoloClient,
new ProviderInternalBaseWallet([deployerAccount], {
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: gasPayerAccount.privateKey
gasPayer: {
gasPayerPrivateKey: gasPayerAccount.privateKey
}
}),
true
Expand Down
2 changes: 1 addition & 1 deletion docs/diagrams/architecture/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ classDiagram
+Address origin
+Uint8Array signature?
+Transaction decode(Uint8Array rawTransaction, boolean isSigned)$
+Blake2b256 getTransactionHash(Address delegator?)
+Blake2b256 getTransactionHash(Address gasPayer?)
+VTHO intrinsicGas(TransactionClause[] clauses)$
+boolean isValidBody(TransactionBody body)$
+Transaction of(TransactionBody: body, Uint8Array signature?)$
Expand Down
9 changes: 3 additions & 6 deletions docs/examples/contracts/contract-delegation-ERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import {
type ProviderInternalWalletAccount,
THOR_SOLO_URL,
ThorClient,
type TransactionReceipt,
VeChainProvider,
type VeChainSigner
VeChainProvider
} from '@vechain/sdk-network';
import { expect } from 'expect';

Expand Down Expand Up @@ -36,9 +34,8 @@ const thorSoloClient = ThorClient.at(THOR_SOLO_URL);
const provider = new VeChainProvider(
thorSoloClient,
new ProviderInternalBaseWallet([deployerAccount], {
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: gasPayerAccount.privateKey
gasPayer: {
gasPayerPrivateKey: gasPayerAccount.privateKey
}
}),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@vechain/sdk-network';
import { expect } from 'expect';

// START_SNIPPET: FullFlowDelegatorPrivateKeySnippet
// START_SNIPPET: FullFlowGasPayerPrivateKeySnippet

// 1 - Create the thor client
const thorSoloClient = ThorClient.at(THOR_SOLO_URL, {
Expand Down Expand Up @@ -50,9 +50,8 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: gasPayerAccount.privateKey
gasPayer: {
gasPayerPrivateKey: gasPayerAccount.privateKey
}
}
),
Expand Down Expand Up @@ -115,7 +114,7 @@ const txReceipt = await thorSoloClient.transactions.waitForTransaction(
sendTransactionResult.id
);

// END_SNIPPET: FullFlowDelegatorPrivateKeySnippet
// END_SNIPPET: FullFlowGasPayerPrivateKeySnippet

// Check the signed transaction
expect(delegatedSigned.isSigned).toEqual(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@vechain/sdk-network';
import { expect } from 'expect';

// START_SNIPPET: FullFlowDelegatorUrlSnippet
// START_SNIPPET: FullFlowGasPayerServiceUrlSnippet

// 1 - Create the thor client
const thorClient = ThorClient.at(TESTNET_URL, {
Expand Down Expand Up @@ -54,9 +54,8 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorUrl: gasPayerAccount.URL
gasPayer: {
gasPayerServiceUrl: gasPayerAccount.URL
}
}
),
Expand Down Expand Up @@ -119,12 +118,12 @@ const txReceipt = await thorClient.transactions.waitForTransaction(
sendTransactionResult.id
);

// END_SNIPPET: FullFlowDelegatorUrlSnippet
// END_SNIPPET: FullFlowGasPayerServiceUrlSnippet

// Check the signed transaction
expect(delegatedSigned.isSigned).toEqual(true);
expect(delegatedSigned.isDelegated).toEqual(true);
// expect(signedTx.delegator).toEqual(gasPayerAccount.address); ---
// expect(signedTx.gasPayer).toEqual(gasPayerAccount.address); ---

// Check the transaction receipt
expect(txReceipt).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@vechain/sdk-network';
import { expect } from 'expect';

// START_SNIPPET: FullFlowNoDelegatorSnippet
// START_SNIPPET: FullFlowNoGasPayerSnippet

// 1 - Create the thor client
const thorSoloClient = ThorClient.at(THOR_SOLO_URL, {
Expand Down Expand Up @@ -95,7 +95,7 @@ const txReceipt = await thorSoloClient.transactions.waitForTransaction(
sendTransactionResult.id
);

// END_SNIPPET: FullFlowNoDelegatorSnippet
// END_SNIPPET: FullFlowNoGasPayerSnippet

// Check the transaction receipt
expect(txReceipt).toBeDefined();
Expand Down
10 changes: 5 additions & 5 deletions docs/templates/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ In the following complete examples, we will explore the entire lifecycle of a Ve

1. **No Delegation (Signing Only with an Origin Private Key)**: In this scenario, we'll demonstrate the basic process of creating a transaction, signing it with the origin private key, and sending it to the VeChainThor blockchain without involving fee delegation.

[FullFlowNoDelegatorSnippet](examples/transactions/full-flow-no-delegator.ts)
[FullFlowNoGasPayerSnippet](examples/transactions/full-flow-no-gas-payer.ts)

2. **Delegation with Private Key**: Here, we'll extend the previous example by incorporating fee delegation. The transaction sender will delegate the transaction fee payment to another entity (delegator), and we'll guide you through the steps of building, signing, and sending such a transaction.
2. **Delegation with Private Key**: Here, we'll extend the previous example by incorporating fee delegation. The transaction sender will delegate the transaction fee payment to another entity (gasPayer), and we'll guide you through the steps of building, signing, and sending such a transaction.

[FullFlowDelegatorPrivateKeySnippet](examples/transactions/full-flow-delegator-private-key.ts)
[FullFlowGasPayerPrivateKeySnippet](examples/transactions/full-flow-gas-payer-private-key.ts)

3. **Delegation with URL**: This example will showcase the use of a delegation URL for fee delegation. The sender will specify a delegation URL in the `signTransaction` options, allowing a designated sponsor to pay the transaction fee. We'll cover the full process, from building clauses to verifying the transaction on-chain.

[FullFlowDelegatorUrlSnippet](examples/transactions/full-flow-delegator-url.ts)
[FullFlowGasPayerServiceUrlSnippet](examples/transactions/full-flow-gas-payer-service-url.ts)

By examining these complete examples, developers can gain a comprehensive understanding of transaction handling in the VeChain SDK. Each example demonstrates the steps involved in initiating, signing, and sending transactions, as well as the nuances associated with fee delegation.

Expand All @@ -78,4 +78,4 @@ Even when using the `simulateTransaction` method you can find the revert reason.

[RevertReasonSimulationSnippet](examples/transactions/revert-reason-with-simulation.ts)

In this case there is only a `TransactionSimulationResult`, so no need to loop.
In this case there is only a `TransactionSimulationResult`, so no need to loop.
Loading
Loading