Skip to content

Commit 05fd293

Browse files
Chore/bnc 4 backport (#1822)
* chore: backport * chore: fix * chore: backport * chore: force checks * chore: gitleeks * chore: gitleeks * chore: gha to include gitleaks ignore * chore: bnc 3 backport * chore: bnc 3 backport * chore: bnc 3 backport * chore: bnc 4 backport --------- Signed-off-by: Luca Nicola Debiasi <63785793+lucanicoladebiasi@users.noreply.github.com> Co-authored-by: clayton neal <clayton.neal@vechain.org>
1 parent 5728313 commit 05fd293

File tree

20 files changed

+128
-109
lines changed

20 files changed

+128
-109
lines changed

apps/sdk-hardhat-integration/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Note that:
2121
- The network name should contain `vechain`, otherwise, it may result in an error.
2222
- 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.
2323
- **Debug Mode**: The `debug` field enables or disables debug mode.
24-
- **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`.
24+
- **Gas Payer**: The `gasPayer` field allows you to delegate the transaction to a gasPayer. It supports two optional parameters: `gasPayerPrivateKey` and `gasPayerServiceUrl`.
2525
- 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.
2626

2727
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.

apps/sdk-hardhat-integration/hardhat.config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const config: HardhatUserConfig = {
7676
/**
7777
* Testnet configuration - with gasPayer url
7878
*/
79-
vechain_testnet_delegator_url: {
79+
vechain_testnet_gas_payer_url: {
8080
// Testnet
8181
url: 'https://testnet.vechain.org',
8282
accounts: {
@@ -103,7 +103,7 @@ const config: HardhatUserConfig = {
103103
/**
104104
* Testnet configuration - with gasPayer private key
105105
*/
106-
vechain_testnet_delegator_private_key: {
106+
vechain_testnet_gas_payer_private_key: {
107107
// Testnet
108108
url: 'https://testnet.vechain.org',
109109
accounts: {
@@ -159,7 +159,7 @@ const config: HardhatUserConfig = {
159159
initialIndex: 0
160160
},
161161
debug: true,
162-
delegator: undefined,
162+
gasPayer: undefined,
163163
gas: 'auto',
164164
gasPrice: 'auto',
165165
gasMultiplier: 1,

localstack/init/kms.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

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

77
# 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)
88
# 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\"}]"
99

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

13-
# Delegator key
14-
awslocal kms create-key --key-usage SIGN_VERIFY --key-spec ECC_SECG_P256K1 --tags "[{\"TagKey\":\"_custom_id_\",\"TagValue\":\"$CUSTOM_DELEGATOR_ID\"}]"
13+
# Gas-Payer key
14+
awslocal kms create-key --key-usage SIGN_VERIFY --key-spec ECC_SECG_P256K1 --tags "[{\"TagKey\":\"_custom_id_\",\"TagValue\":\"$CUSTOM_GAS_PAYER_ID\"}]"

packages/aws-kms-adapter/README.md

+39-38
Original file line numberDiff line numberDiff line change
@@ -163,45 +163,46 @@ import {
163163
THOR_SOLO_URL,
164164
ThorClient
165165
} from '@vechain/sdk-network';
166-
...
167-
const awsClientParameters: KMSClientParameters = {
168-
keyId: 'keyId',
169-
region: 'region',
170-
credentials: {
171-
accessKeyId: 'accessKeyId',
172-
secretAccessKey: 'secretAccessKey'
173-
},
174-
endpoint: 'localstackEndpoint'
175-
};
176166

177-
const delegatorAwsClientParameters: KMSClientParameters = {
178-
// Same format as awsClientParameters, changing values so we can connect
179-
// to something different to LocalStack if we want (see examples above)
167+
...
168+
const awsClientParameters: KMSClientParameters = {
169+
keyId: 'keyId',
170+
region: 'region',
171+
credentials: {
172+
accessKeyId: 'accessKeyId',
173+
secretAccessKey: 'secretAccessKey'
174+
},
175+
endpoint: 'localstackEndpoint'
176+
};
177+
178+
const gasPayerAwsClientParameters: KMSClientParameters = {
179+
// Same format as awsClientParameters, changing values so we can connect
180+
// to something different to LocalStack if we want (see examples above)
181+
}
182+
...
183+
184+
const thorClient = ThorClient.fromUrl(THOR_SOLO_URL);
185+
const provider = new KMSVeChainProvider(
186+
thorClient,
187+
awsClientParameters
188+
);
189+
190+
// Signer with gasPayer enabled
191+
const gasPayerProvider = new KMSVeChainProvider(
192+
thorClient,
193+
gasPayerAwsClientParameters
194+
);
195+
const signerWithGasPayer = new KMSVeChainSigner(
196+
provider,
197+
{
198+
provider: gasPayerProvider
180199
}
181-
...
200+
);
182201

183-
const thorClient = ThorClient.fromUrl(THOR_SOLO_URL);
184-
const provider = new KMSVeChainProvider(
185-
thorClient,
186-
awsClientParameters
187-
);
188-
189-
// Signer with gasPayer enabled
190-
const delegatorProvider = new KMSVeChainProvider(
191-
thorClient,
192-
delegatorAwsClientParameters
193-
);
194-
const signerWithDelegator = new KMSVeChainSigner(
195-
provider,
196-
{
197-
provider: delegatorProvider
198-
}
199-
);
200-
201-
// Returns the address related to the origin KMS key
202-
const address = await signerWithDelegator.getAddress();
203-
// Returns the address related to the gasPayer KMS key
204-
const address = await signerWithDelegator.getAddress(true);
202+
// Returns the address related to the origin KMS key
203+
const address = await signerWithGasPayer.getAddress();
204+
// Returns the address related to the gasPayer KMS key
205+
const address = await signerWithGasPayer.getAddress(true);
205206
```
206207

207208
### Delegation (url)
@@ -233,15 +234,15 @@ import {
233234
thorClient,
234235
awsClientParameters
235236
);
236-
const signerWithDelegator = new KMSVeChainSigner(
237+
const signerWithGasPayer = new KMSVeChainSigner(
237238
provider,
238239
{
239240
url: 'https://sponsor-testnet.vechain.energy/by/705'
240241
}
241242
);
242243

243244
// Returns the address related to the origin KMS key
244-
const address = await signerWithDelegator.getAddress();
245+
const address = await signerWithGasPayer.getAddress();
245246

246247
// See /tests folder for more examples. This time we wont get the address
247248
// of the gasPayer since there is no provider

packages/aws-kms-adapter/src/KMSVeChainSigner.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import { KMSVeChainProvider } from './KMSVeChainProvider';
2121

2222
class KMSVeChainSigner extends VeChainAbstractSigner {
2323
private readonly kmsVeChainProvider?: KMSVeChainProvider;
24-
private readonly kmsVeChainDelegatorProvider?: KMSVeChainProvider;
25-
private readonly kmsVeChainDelegatorUrl?: string;
24+
private readonly kmsVeChainGasPayerProvider?: KMSVeChainProvider;
25+
private readonly kmsVeChainGasPayerServiceUrl?: string;
2626

2727
public constructor(
2828
provider?: AvailableVeChainProviders,
29-
delegator?: {
29+
gasPayer?: {
3030
provider?: AvailableVeChainProviders;
3131
url?: string;
3232
}
@@ -44,20 +44,20 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
4444
this.kmsVeChainProvider = this.provider;
4545
}
4646

47-
// Delegator provider, if any
48-
if (delegator !== undefined) {
47+
// Gas-payer provider, if any
48+
if (gasPayer !== undefined) {
4949
if (
50-
delegator.provider !== undefined &&
51-
delegator.provider instanceof KMSVeChainProvider
50+
gasPayer.provider !== undefined &&
51+
gasPayer.provider instanceof KMSVeChainProvider
5252
) {
53-
this.kmsVeChainDelegatorProvider = delegator.provider;
54-
} else if (delegator.url !== undefined) {
55-
this.kmsVeChainDelegatorUrl = delegator.url;
53+
this.kmsVeChainGasPayerProvider = gasPayer.provider;
54+
} else if (gasPayer.url !== undefined) {
55+
this.kmsVeChainGasPayerServiceUrl = gasPayer.url;
5656
} else {
5757
throw new JSONRPCInvalidParams(
5858
'KMSVeChainSigner.constructor',
5959
'The gasPayer object is not well formed, either provider or url should be provided.',
60-
{ delegator }
60+
{ gasPayer: gasPayer }
6161
);
6262
}
6363
}
@@ -132,15 +132,15 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
132132

133133
/**
134134
* It returns the address associated with the signer.
135-
* @param {boolean} fromDelegatorProvider (Optional) If true, the provider will be the gasPayer.
135+
* @param {boolean} fromGasPayerProvider (Optional) If true, the provider will be the gasPayer.
136136
* @returns The address associated with the signer.
137137
*/
138138
public async getAddress(
139-
fromDelegatorProvider: boolean | undefined = false
139+
fromGasPayerProvider: boolean | undefined = false
140140
): Promise<string> {
141141
try {
142-
const kmsProvider = fromDelegatorProvider
143-
? this.kmsVeChainDelegatorProvider
142+
const kmsProvider = fromGasPayerProvider
143+
? this.kmsVeChainGasPayerProvider
144144
: this.kmsVeChainProvider;
145145
const publicKeyDecoded =
146146
await this.getDecodedPublicKey(kmsProvider);
@@ -149,7 +149,7 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
149149
throw new SignerMethodError(
150150
'KMSVeChainSigner.getAddress',
151151
'The address could not be retrieved.',
152-
{ fromDelegatorProvider },
152+
{ fromGasPayerProvider: fromGasPayerProvider },
153153
error
154154
);
155155
}
@@ -247,32 +247,32 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
247247
await this.buildVeChainSignatureFromPayload(transactionHash);
248248

249249
// We try first in case there is a gasPayer provider
250-
if (this.kmsVeChainDelegatorProvider !== undefined) {
250+
if (this.kmsVeChainGasPayerProvider !== undefined) {
251251
const publicKeyDecoded = await this.getDecodedPublicKey();
252252
const originAddress = Address.ofPublicKey(publicKeyDecoded);
253253
const delegatedHash =
254254
transaction.getTransactionHash(originAddress).bytes;
255-
const delegatorSignature =
255+
const gasPayerSignature =
256256
await this.buildVeChainSignatureFromPayload(
257257
delegatedHash,
258-
this.kmsVeChainDelegatorProvider
258+
this.kmsVeChainGasPayerProvider
259259
);
260-
return concatBytes(originSignature, delegatorSignature);
260+
return concatBytes(originSignature, gasPayerSignature);
261261
} else if (
262262
// If not, we try with the gasPayer URL
263-
this.kmsVeChainDelegatorUrl !== undefined &&
263+
this.kmsVeChainGasPayerServiceUrl !== undefined &&
264264
this.provider !== undefined
265265
) {
266266
const originAddress = await this.getAddress();
267-
const delegatorSignature = await DelegationHandler({
268-
gasPayerServiceUrl: this.kmsVeChainDelegatorUrl
267+
const gasPayerSignature = await DelegationHandler({
268+
gasPayerServiceUrl: this.kmsVeChainGasPayerServiceUrl
269269
}).getDelegationSignatureUsingUrl(
270270
transaction,
271271
originAddress,
272272
this.provider.thorClient.httpClient
273273
);
274274

275-
return concatBytes(originSignature, delegatorSignature);
275+
return concatBytes(originSignature, gasPayerSignature);
276276
}
277277

278278
return originSignature;

packages/aws-kms-adapter/tests/KMSVeChainSigner.solo.test.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('KMSVeChainSigner - Thor Solo', () => {
4848
/**
4949
* KMSVeChainSigner with gasPayer instance
5050
*/
51-
let signerWithDelegator: KMSVeChainSigner;
51+
let signerWithGasPayer: KMSVeChainSigner;
5252

5353
/**
5454
* Init thor client and provider before all tests
@@ -59,9 +59,9 @@ describe('KMSVeChainSigner - Thor Solo', () => {
5959
'./aws-credentials.json'
6060
);
6161
let awsClientParameters: KMSClientParameters;
62-
let delegatorAwsClientParameters: KMSClientParameters;
62+
let gasPayerAwsClientParameters: KMSClientParameters;
6363
try {
64-
[awsClientParameters, delegatorAwsClientParameters] = JSON.parse(
64+
[awsClientParameters, gasPayerAwsClientParameters] = JSON.parse(
6565
fs.readFileSync(awsCredentialsPath, 'utf8')
6666
) as KMSClientParameters[];
6767
} catch (error) {
@@ -70,7 +70,7 @@ describe('KMSVeChainSigner - Thor Solo', () => {
7070
__dirname,
7171
'./test-aws-credentials.json'
7272
);
73-
[awsClientParameters, delegatorAwsClientParameters] = JSON.parse(
73+
[awsClientParameters, gasPayerAwsClientParameters] = JSON.parse(
7474
fs.readFileSync(testAwsCredentialsPath, 'utf8')
7575
) as KMSClientParameters[];
7676
}
@@ -85,19 +85,19 @@ describe('KMSVeChainSigner - Thor Solo', () => {
8585
await fundVTHO(thorClient, expectedAddress);
8686

8787
// Signer with gasPayer enabled
88-
const delegatorProvider = new KMSVeChainProvider(
88+
const gasPayerProvider = new KMSVeChainProvider(
8989
thorClient,
90-
delegatorAwsClientParameters
90+
gasPayerAwsClientParameters
9191
);
92-
expect(delegatorProvider).toBeInstanceOf(KMSVeChainProvider);
93-
signerWithDelegator = new KMSVeChainSigner(
92+
expect(gasPayerProvider).toBeInstanceOf(KMSVeChainProvider);
93+
signerWithGasPayer = new KMSVeChainSigner(
9494
new KMSVeChainProvider(thorClient, awsClientParameters, true),
9595
{
96-
provider: delegatorProvider
96+
provider: gasPayerProvider
9797
}
9898
);
9999
// This step should be removed once this is clarified https://github.com/localstack/localstack/issues/11678
100-
await fundVTHO(thorClient, await signerWithDelegator.getAddress(true));
100+
await fundVTHO(thorClient, await signerWithGasPayer.getAddress(true));
101101
}, timeout);
102102

103103
describe('getAddress', () => {
@@ -120,7 +120,7 @@ describe('KMSVeChainSigner - Thor Solo', () => {
120120
description,
121121
async () => {
122122
const signTransactionSigner = isDelegated
123-
? signerWithDelegator
123+
? signerWithGasPayer
124124
: signer;
125125
const sampleClause = Clause.callFunction(
126126
Address.of(TESTING_CONTRACT_ADDRESS),
@@ -187,7 +187,7 @@ describe('KMSVeChainSigner - Thor Solo', () => {
187187
description,
188188
async () => {
189189
const signTransactionSigner = isDelegated
190-
? signerWithDelegator
190+
? signerWithGasPayer
191191
: signer;
192192
const sampleClause = Clause.callFunction(
193193
Address.of(TESTING_CONTRACT_ADDRESS),

packages/aws-kms-adapter/tests/KMSVeChainSigner.testnet.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('KMSVeChainSigner - Testnet', () => {
3838
/**
3939
* KMSVeChainSigner with gasPayer instance
4040
*/
41-
let signerWithDelegator: KMSVeChainSigner;
41+
let signerWithGasPayer: KMSVeChainSigner;
4242

4343
/**
4444
* Init thor client and provider before all tests
@@ -65,7 +65,7 @@ describe('KMSVeChainSigner - Testnet', () => {
6565
}
6666
thorClient = ThorClient.at(TESTNET_URL);
6767

68-
signerWithDelegator = new KMSVeChainSigner(
68+
signerWithGasPayer = new KMSVeChainSigner(
6969
new KMSVeChainProvider(thorClient, awsClientParameters, true),
7070
{
7171
url: TESTNET_DELEGATE_URL
@@ -74,14 +74,14 @@ describe('KMSVeChainSigner - Testnet', () => {
7474

7575
await addAddressToFeeDelegationWhitelist(
7676
thorClient,
77-
await signerWithDelegator.getAddress()
77+
await signerWithGasPayer.getAddress()
7878
);
7979
}, 4 * timeout);
8080

8181
afterAll(async () => {
8282
await removeAddressFromFeeDelegationWhitelist(
8383
thorClient,
84-
await signerWithDelegator.getAddress()
84+
await signerWithGasPayer.getAddress()
8585
);
8686
}, 4 * timeout);
8787

@@ -112,7 +112,7 @@ describe('KMSVeChainSigner - Testnet', () => {
112112
) as TransactionClause;
113113

114114
const originAddress =
115-
await signerWithDelegator.getAddress();
115+
await signerWithGasPayer.getAddress();
116116

117117
const gasResult = await thorClient.gas.estimateGas(
118118
[sampleClause],
@@ -129,7 +129,7 @@ describe('KMSVeChainSigner - Testnet', () => {
129129
);
130130

131131
const signedRawTx =
132-
await signerWithDelegator.signTransaction(
132+
await signerWithGasPayer.signTransaction(
133133
signerUtils.transactionBodyToTransactionRequestInput(
134134
txBody,
135135
originAddress

0 commit comments

Comments
 (0)