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

1658 bnc part 4 #1809

Merged
merged 63 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f842d6b
fix: fix BNC...
lucanicoladebiasi Jan 29, 2025
186667c
fix: fix BNC...
lucanicoladebiasi Jan 29, 2025
517e9cd
fix: fix BNC...
lucanicoladebiasi Jan 29, 2025
8743c13
fix: fix BNC...
lucanicoladebiasi Jan 29, 2025
c2f560c
fix: fix BNC...
lucanicoladebiasi Jan 30, 2025
6a5f9b1
fix: fix BNC...
lucanicoladebiasi Jan 30, 2025
74447ca
Merge branch 'main' into 1658-bnc
lucanicoladebiasi Jan 30, 2025
688b52f
Merge branch '1658-bnc' into 1658-bnc---part-2
lucanicoladebiasi Feb 4, 2025
c970688
Merge branch 'main' into 1658-bnc---part-2
lucanicoladebiasi Feb 5, 2025
c3b0ac3
fix: en_7 recommendations... (#1749)
lucanicoladebiasi Feb 5, 2025
1db6c95
fix: BNC (network)
lucanicoladebiasi Feb 6, 2025
41c5356
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
0f57e12
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
8a411a7
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
1b7076d
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
9a8965e
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
e39f0d4
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
be836d4
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
99bcb28
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
5666047
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
abfdab3
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
220008d
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
57e1dfe
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
3f54e7f
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
6283023
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
b22584c
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
fa764a2
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
40aba92
fix: BNC 2 network
lucanicoladebiasi Feb 6, 2025
4bd5d23
fix: BNC 2 network
lucanicoladebiasi Feb 7, 2025
4a982dc
fix: BNC 2 network
lucanicoladebiasi Feb 7, 2025
a057c1f
fix: BNC 2 network
lucanicoladebiasi Feb 7, 2025
7b3ed2c
fix: BNC 2 network
lucanicoladebiasi Feb 7, 2025
d45db89
fix: BNC 2 network
lucanicoladebiasi Feb 7, 2025
593cd92
fix: BNC 2 network
lucanicoladebiasi Feb 7, 2025
b16343b
fix: BNC 2 network
lucanicoladebiasi Feb 7, 2025
f8cc404
fix: BNC 2 network
lucanicoladebiasi Feb 7, 2025
6511531
Update packages/rpc-proxy/src/utils/config-validator/config-validator.ts
lucanicoladebiasi Feb 7, 2025
c576e85
Update packages/rpc-proxy/src/utils/config-validator/config-validator.ts
lucanicoladebiasi Feb 7, 2025
c5ea205
fix: BNC 2 network
lucanicoladebiasi Feb 7, 2025
105ca6c
fix: `BNC` part 2 - network refactor
lucanicoladebiasi Jan 31, 2025
2a73fd0
fix: `BNC` part 2 - network refactor
lucanicoladebiasi Feb 8, 2025
560c4e5
fix: `BNC` part 2 - network refactor
lucanicoladebiasi Feb 10, 2025
45278fb
fix: `BNC` part 2 - network refactor
lucanicoladebiasi Feb 10, 2025
e5a225e
fix: `BNC` part 3 - rpc-proxy refactor
lucanicoladebiasi Feb 10, 2025
376b086
fix: `BNC` part 3 - rpc-proxy refactor
lucanicoladebiasi Feb 10, 2025
ed7a0e7
fix: `BNC` part 3 - rpc-proxy refactor
lucanicoladebiasi Feb 10, 2025
386c04a
fix: `BNC` part 3 - rpc-proxy refactor
lucanicoladebiasi Feb 10, 2025
cfddf76
fix: `BNC` part 3 - rpc-proxy refactor
lucanicoladebiasi Feb 10, 2025
961659e
fix: `BNC` part 2 - openssl fix
lucanicoladebiasi Feb 10, 2025
569ac46
fix: `BNC` part 2 - openssl fix
lucanicoladebiasi Feb 10, 2025
2f1f397
fix: `BNC` part 2 - rpc-proxy README.md amended
lucanicoladebiasi Feb 11, 2025
2b03ef2
Merge branch '1658-bnc---part-2' into 1658-bnc---part-3
lucanicoladebiasi Feb 11, 2025
e6a23f7
Merge branch 'main' into 1658-bnc---part-3
lucanicoladebiasi Feb 11, 2025
96daa14
fix: `BNC` parts 4, 5 - delegator reintroduced for `TransactionsExpan…
lucanicoladebiasi Feb 12, 2025
36a876d
fix: `BNC` parts 4, 5 - delegator reintroduced for `TransactionsExpan…
lucanicoladebiasi Feb 12, 2025
34a5336
fix: `BNC` parts 4, 5 - hardhat-plugin refactor
lucanicoladebiasi Feb 12, 2025
b226778
fix: `BNC` parts 4 - hardhat-plugin refactor
lucanicoladebiasi Feb 12, 2025
f1e3adb
Merge remote-tracking branch 'origin/1658-bnc---part-4' into 1658-bnc…
lucanicoladebiasi Feb 12, 2025
4403ff6
fix: `BNC` parts 4 - aws-kms-adapter refactor
lucanicoladebiasi Feb 12, 2025
08cdc63
fix: `BNC` parts 4 - aws-kms-adapter refactor
lucanicoladebiasi Feb 12, 2025
ab8fb5f
Merge branch 'main' into 1658-bnc---part-4
lucanicoladebiasi Feb 13, 2025
68dc209
Update apps/sdk-hardhat-integration/README.md
lucanicoladebiasi Feb 13, 2025
35e3abd
Update README.md
lucanicoladebiasi Feb 13, 2025
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
2 changes: 1 addition & 1 deletion apps/sdk-hardhat-integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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: `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 `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`.
- **Gas Payer**: The `gasPayer` field allows you to delegate the transaction to a gasPayer. It supports two optional parameters: - **Gas Payer**: The `gasPayer` field allows you to delegate the transaction to a gasPayer. It supports two optional parameters: `gasPayerPrivateKey` and `gasPayerServiceUrl`.
- 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.
6 changes: 3 additions & 3 deletions apps/sdk-hardhat-integration/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const config: HardhatUserConfig = {
/**
* Testnet configuration - with gasPayer url
*/
vechain_testnet_delegator_url: {
vechain_testnet_gas_payer_url: {
// Testnet
url: 'https://testnet.vechain.org',
accounts: {
Expand All @@ -103,7 +103,7 @@ const config: HardhatUserConfig = {
/**
* Testnet configuration - with gasPayer private key
*/
vechain_testnet_delegator_private_key: {
vechain_testnet_gas_payer_private_key: {
// Testnet
url: 'https://testnet.vechain.org',
accounts: {
Expand Down Expand Up @@ -159,7 +159,7 @@ const config: HardhatUserConfig = {
initialIndex: 0
},
debug: true,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
Expand Down
6 changes: 3 additions & 3 deletions localstack/init/kms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

CUSTOM_ORIGIN_KEY_MATERIAL="f5KQzETF/SuV/iHWrW/l+pwXfhzW87TJapexPgnqoVg="
CUSTOM_ORIGIN_ID="bffb20d8-35ca-4408-9d54-f775b929b38d"
CUSTOM_DELEGATOR_ID="3e47cac8-de37-4f50-b591-57f525c1b05c"
CUSTOM_GAS_PAYER_ID="3e47cac8-de37-4f50-b591-57f525c1b05c"

# The command succeeds but the key is not created with the custom key material (should be fixed once this is clarified: https://github.com/localstack/localstack/issues/11678)
# awslocal kms create-key --key-usage SIGN_VERIFY --key-spec ECC_SECG_P256K1 --tags "[{\"TagKey\":\"_custom_key_material_\",\"TagValue\":\"$CUSTOM_ORIGIN_KEY_MATERIAL\"},{\"TagKey\":\"_custom_id_\",\"TagValue\":\"$CUSTOM_ORIGIN_ID\"}]"

# Origin key
awslocal kms create-key --key-usage SIGN_VERIFY --key-spec ECC_SECG_P256K1 --tags "[{\"TagKey\":\"_custom_id_\",\"TagValue\":\"$CUSTOM_ORIGIN_ID\"}]"

# Delegator key
awslocal kms create-key --key-usage SIGN_VERIFY --key-spec ECC_SECG_P256K1 --tags "[{\"TagKey\":\"_custom_id_\",\"TagValue\":\"$CUSTOM_DELEGATOR_ID\"}]"
# Gas-Payer key
awslocal kms create-key --key-usage SIGN_VERIFY --key-spec ECC_SECG_P256K1 --tags "[{\"TagKey\":\"_custom_id_\",\"TagValue\":\"$CUSTOM_GAS_PAYER_ID\"}]"
79 changes: 40 additions & 39 deletions packages/aws-kms-adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,50 +158,51 @@ import {
You can also use delegation to sign your transactions. In this example the source of the delegation is a gasPayer which key is in KMS so requires a `KMSVeChainProvider`.

```ts
import { type KMSClientParameters, KMSVeChainProvider, KMSVeChainSigner } from '@vechain/sdk-aws-kms-adapter';
import {type KMSClientParameters, KMSVeChainProvider, KMSVeChainSigner} from '@vechain/sdk-aws-kms-adapter';
import {
THOR_SOLO_URL,
ThorClient
} from '@vechain/sdk-network';
...
const awsClientParameters: KMSClientParameters = {
keyId: 'keyId',
region: 'region',
credentials: {
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey'
},
endpoint: 'localstackEndpoint'
};

const delegatorAwsClientParameters: KMSClientParameters = {
// Same format as awsClientParameters, changing values so we can connect
// to something different to LocalStack if we want (see examples above)
...
const awsClientParameters: KMSClientParameters = {
keyId: 'keyId',
region: 'region',
credentials: {
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey'
},
endpoint: 'localstackEndpoint'
};

const gasPayerAwsClientParameters: KMSClientParameters = {
// Same format as awsClientParameters, changing values so we can connect
// to something different to LocalStack if we want (see examples above)
}
...

const thorClient = ThorClient.fromUrl(THOR_SOLO_URL);
const provider = new KMSVeChainProvider(
thorClient,
awsClientParameters
);

// Signer with gasPayer enabled
const gasPayerProvider = new KMSVeChainProvider(
thorClient,
gasPayerAwsClientParameters
);
const signerWithGasPayer = new KMSVeChainSigner(
provider,
{
provider: gasPayerProvider
}
...

const thorClient = ThorClient.fromUrl(THOR_SOLO_URL);
const provider = new KMSVeChainProvider(
thorClient,
awsClientParameters
);

// Signer with gasPayer enabled
const delegatorProvider = new KMSVeChainProvider(
thorClient,
delegatorAwsClientParameters
);
const signerWithDelegator = new KMSVeChainSigner(
provider,
{
provider: delegatorProvider
}
);
);

// Returns the address related to the origin KMS key
const address = await signerWithDelegator.getAddress();
// Returns the address related to the gasPayer KMS key
const address = await signerWithDelegator.getAddress(true);
// Returns the address related to the origin KMS key
const address = await signerWithGasPayer.getAddress();
// Returns the address related to the gasPayer KMS key
const address = await signerWithGasPayer.getAddress(true);
```

### Delegation (url)
Expand Down Expand Up @@ -233,15 +234,15 @@ import {
thorClient,
awsClientParameters
);
const signerWithDelegator = new KMSVeChainSigner(
const signerWithGasPayer = new KMSVeChainSigner(
provider,
{
url: 'https://sponsor-testnet.vechain.energy/by/705'
}
);

// Returns the address related to the origin KMS key
const address = await signerWithDelegator.getAddress();
const address = await signerWithGasPayer.getAddress();

// See /tests folder for more examples. This time we wont get the address
// of the gasPayer since there is no provider
Expand Down
48 changes: 24 additions & 24 deletions packages/aws-kms-adapter/src/KMSVeChainSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

class KMSVeChainSigner extends VeChainAbstractSigner {
private readonly kmsVeChainProvider?: KMSVeChainProvider;
private readonly kmsVeChainDelegatorProvider?: KMSVeChainProvider;
private readonly kmsVeChainDelegatorUrl?: string;
private readonly kmsVeChainGasPayerProvider?: KMSVeChainProvider;
private readonly kmsVeChainGasPayerServiceUrl?: string;

public constructor(
provider?: AvailableVeChainProviders,
delegator?: {
gasPayer?: {
provider?: AvailableVeChainProviders;
url?: string;
}
Expand All @@ -39,20 +39,20 @@
this.kmsVeChainProvider = this.provider;
}

// Delegator provider, if any
if (delegator !== undefined) {
// Gas-payer provider, if any
if (gasPayer !== undefined) {
if (
delegator.provider !== undefined &&
delegator.provider instanceof KMSVeChainProvider
gasPayer.provider !== undefined &&
gasPayer.provider instanceof KMSVeChainProvider
) {
this.kmsVeChainDelegatorProvider = delegator.provider;
} else if (delegator.url !== undefined) {
this.kmsVeChainDelegatorUrl = delegator.url;
this.kmsVeChainGasPayerProvider = gasPayer.provider;
} else if (gasPayer.url !== undefined) {
this.kmsVeChainGasPayerServiceUrl = gasPayer.url;
} else {
throw new JSONRPCInvalidParams(
'KMSVeChainSigner.constructor',
'The gasPayer object is not well formed, either provider or url should be provided.',
{ delegator }
{ gasPayer: gasPayer }

Check warning on line 55 in packages/aws-kms-adapter/src/KMSVeChainSigner.ts

View workflow job for this annotation

GitHub Actions / install-build / Build & Lint

Expected property shorthand
);
}
}
Expand Down Expand Up @@ -127,15 +127,15 @@

/**
* It returns the address associated with the signer.
* @param {boolean} fromDelegatorProvider (Optional) If true, the provider will be the gasPayer.
* @param {boolean} fromGasPayerProvider (Optional) If true, the provider will be the gasPayer.
* @returns The address associated with the signer.
*/
public async getAddress(
fromDelegatorProvider: boolean | undefined = false
fromGasPayerProvider: boolean | undefined = false
): Promise<string> {
try {
const kmsProvider = fromDelegatorProvider
? this.kmsVeChainDelegatorProvider
const kmsProvider = fromGasPayerProvider
? this.kmsVeChainGasPayerProvider
: this.kmsVeChainProvider;
const publicKeyDecoded =
await this.getDecodedPublicKey(kmsProvider);
Expand All @@ -144,7 +144,7 @@
throw new SignerMethodError(
'KMSVeChainSigner.getAddress',
'The address could not be retrieved.',
{ fromDelegatorProvider },
{ fromGasPayerProvider: fromGasPayerProvider },

Check warning on line 147 in packages/aws-kms-adapter/src/KMSVeChainSigner.ts

View workflow job for this annotation

GitHub Actions / install-build / Build & Lint

Expected property shorthand
error
);
}
Expand Down Expand Up @@ -240,32 +240,32 @@
await this.buildVeChainSignatureFromPayload(transactionHash);

// We try first in case there is a gasPayer provider
if (this.kmsVeChainDelegatorProvider !== undefined) {
if (this.kmsVeChainGasPayerProvider !== undefined) {
const publicKeyDecoded = await this.getDecodedPublicKey();
const originAddress = Address.ofPublicKey(publicKeyDecoded);
const delegatedHash =
transaction.getTransactionHash(originAddress).bytes;
const delegatorSignature =
const gasPayerSignature =
await this.buildVeChainSignatureFromPayload(
delegatedHash,
this.kmsVeChainDelegatorProvider
this.kmsVeChainGasPayerProvider
);
return concatBytes(originSignature, delegatorSignature);
return concatBytes(originSignature, gasPayerSignature);
} else if (
// If not, we try with the gasPayer URL
this.kmsVeChainDelegatorUrl !== undefined &&
this.kmsVeChainGasPayerServiceUrl !== undefined &&
this.provider !== undefined
) {
const originAddress = await this.getAddress();
const delegatorSignature = await DelegationHandler({
gasPayerServiceUrl: this.kmsVeChainDelegatorUrl
const gasPayerSignature = await DelegationHandler({
gasPayerServiceUrl: this.kmsVeChainGasPayerServiceUrl
}).getDelegationSignatureUsingUrl(
transaction,
originAddress,
this.provider.thorClient.httpClient
);

return concatBytes(originSignature, delegatorSignature);
return concatBytes(originSignature, gasPayerSignature);
}

return originSignature;
Expand Down
24 changes: 12 additions & 12 deletions packages/aws-kms-adapter/tests/KMSVeChainSigner.solo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('KMSVeChainSigner - Thor Solo', () => {
/**
* KMSVeChainSigner with gasPayer instance
*/
let signerWithDelegator: KMSVeChainSigner;
let signerWithGasPayer: KMSVeChainSigner;

/**
* Init thor client and provider before all tests
Expand All @@ -64,9 +64,9 @@ describe('KMSVeChainSigner - Thor Solo', () => {
'./aws-credentials.json'
);
let awsClientParameters: KMSClientParameters;
let delegatorAwsClientParameters: KMSClientParameters;
let gasPayerAwsClientParameters: KMSClientParameters;
try {
[awsClientParameters, delegatorAwsClientParameters] = JSON.parse(
[awsClientParameters, gasPayerAwsClientParameters] = JSON.parse(
fs.readFileSync(awsCredentialsPath, 'utf8')
) as KMSClientParameters[];
} catch (error) {
Expand All @@ -75,7 +75,7 @@ describe('KMSVeChainSigner - Thor Solo', () => {
__dirname,
'./test-aws-credentials.json'
);
[awsClientParameters, delegatorAwsClientParameters] = JSON.parse(
[awsClientParameters, gasPayerAwsClientParameters] = JSON.parse(
fs.readFileSync(testAwsCredentialsPath, 'utf8')
) as KMSClientParameters[];
}
Expand All @@ -90,19 +90,19 @@ describe('KMSVeChainSigner - Thor Solo', () => {
await fundVTHO(thorClient, expectedAddress);

// Signer with gasPayer enabled
const delegatorProvider = new KMSVeChainProvider(
const gasPayerProvider = new KMSVeChainProvider(
thorClient,
delegatorAwsClientParameters
gasPayerAwsClientParameters
);
expect(delegatorProvider).toBeInstanceOf(KMSVeChainProvider);
signerWithDelegator = new KMSVeChainSigner(
expect(gasPayerProvider).toBeInstanceOf(KMSVeChainProvider);
signerWithGasPayer = new KMSVeChainSigner(
new KMSVeChainProvider(thorClient, awsClientParameters, true),
{
provider: delegatorProvider
provider: gasPayerProvider
}
);
// This step should be removed once this is clarified https://github.com/localstack/localstack/issues/11678
await fundVTHO(thorClient, await signerWithDelegator.getAddress(true));
await fundVTHO(thorClient, await signerWithGasPayer.getAddress(true));
}, timeout);

describe('getAddress', () => {
Expand All @@ -125,7 +125,7 @@ describe('KMSVeChainSigner - Thor Solo', () => {
description,
async () => {
const signTransactionSigner = isDelegated
? signerWithDelegator
? signerWithGasPayer
: signer;
const sampleClause = Clause.callFunction(
Address.of(TESTING_CONTRACT_ADDRESS),
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('KMSVeChainSigner - Thor Solo', () => {
description,
async () => {
const signTransactionSigner = isDelegated
? signerWithDelegator
? signerWithGasPayer
: signer;
const sampleClause = Clause.callFunction(
Address.of(TESTING_CONTRACT_ADDRESS),
Expand Down
Loading
Loading