Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into 1484-net
Browse files Browse the repository at this point in the history
  • Loading branch information
lucanicoladebiasi committed Jan 10, 2025
2 parents b5d7050 + 560f00f commit 168786c
Show file tree
Hide file tree
Showing 41 changed files with 390 additions and 408 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ updates:
day: "wednesday"
pull-request-branch-name:
separator: "-"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
day: "wednesday"
target-branch: "1.0.0"
pull-request-branch-name:
separator: "-"
5 changes: 4 additions & 1 deletion .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: Check for leaks in secrets
on:
pull_request:
branches:
- main
- 'main'
- 'main-*'
- 'supported-*'
- 'feature-*'

permissions:
contents: read # This is required for actions/checkout
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/on-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- 'main'
- 'main-*'
- 'supported-*'
- 'feature-*'

jobs:
install-build:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ name: PR Checks
on:
pull_request:
branches:
- main
- 'main'
- 'main-*'
- 'supported-*'
- 'feature-*'

jobs:
doc-examples:
Expand Down
2 changes: 1 addition & 1 deletion .github/LICENSE.md → LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 vechain
Copyright (c) 2025 VeChain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions apps/sdk-cloudflare-integration/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdk-cloudflare-integration",
"description": "An example app of how to integrate the VeChain SDK with Cloudflare Workers",
"version": "1.0.0-rc.5",
"version": "2.0.0-beta.1",
"private": true,
"author": "VeChain Foundation",
"license": "MIT",
Expand All @@ -16,6 +16,6 @@
"wrangler": "^3.72.3"
},
"dependencies": {
"@vechain/sdk-core": "1.0.0-rc.5"
"@vechain/sdk-core": "2.0.0-beta.1"
}
}
8 changes: 4 additions & 4 deletions apps/sdk-hardhat-integration/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdk-hardhat-integration",
"description": "An example app of how to use the @vechain/sdk-hardhat-plugin to interact with the VeChainThor blockchain",
"version": "1.0.0-rc.5",
"version": "2.0.0-beta.1",
"private": true,
"main": "index.js",
"author": "VeChain Foundation",
Expand All @@ -18,9 +18,9 @@
},
"dependencies": {
"@openzeppelin/contracts": "^5.1.0",
"@vechain/sdk-core": "1.0.0-rc.5",
"@vechain/sdk-hardhat-plugin": "1.0.0-rc.5",
"@vechain/sdk-logging": "1.0.0-rc.5"
"@vechain/sdk-core": "2.0.0-beta.1",
"@vechain/sdk-hardhat-plugin": "2.0.0-beta.1",
"@vechain/sdk-logging": "2.0.0-beta.1"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions apps/sdk-nextjs-integration/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdk-nextjs-integration",
"description": "An example app of how to integrate the VeChain SDK with Next.js",
"version": "1.0.0-rc.5",
"version": "2.0.0-beta.1",
"private": true,
"author": "VeChain Foundation",
"license": "MIT",
Expand All @@ -15,8 +15,8 @@
"test:e2e": "playwright test"
},
"dependencies": {
"@vechain/sdk-core": "1.0.0-rc.5",
"@vechain/sdk-network": "1.0.0-rc.5",
"@vechain/sdk-core": "2.0.0-beta.1",
"@vechain/sdk-network": "2.0.0-beta.1",
"install": "^0.13.0",
"next": "15.1.2",
"react": "^18",
Expand Down
6 changes: 3 additions & 3 deletions apps/sdk-node-integration/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdk-node-integration",
"description": "An example app of how to integrate the VeChain SDK with Node.js",
"version": "1.0.0-rc.5",
"version": "2.0.0-beta.1",
"private": true,
"main": "dist/index.js",
"types": "src/index.ts",
Expand All @@ -13,7 +13,7 @@
"test": "jest"
},
"dependencies": {
"@vechain/sdk-network": "1.0.0-rc.5"
"@vechain/sdk-network": "2.0.0-beta.1"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand All @@ -22,4 +22,4 @@
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
}
}
}
6 changes: 3 additions & 3 deletions apps/sdk-vite-integration/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdk-vite-integration",
"private": true,
"version": "1.0.0-rc.5",
"version": "2.0.0-beta.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -12,8 +12,8 @@
"test:e2e": "playwright test"
},
"dependencies": {
"@vechain/sdk-core": "1.0.0-rc.5",
"@vechain/sdk-network": "1.0.0-rc.5",
"@vechain/sdk-core": "2.0.0-beta.1",
"@vechain/sdk-network": "2.0.0-beta.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.27.0"
Expand Down
21 changes: 0 additions & 21 deletions dependabot.yml

This file was deleted.

6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "1.0.0-rc.5",
"version": "2.0.0-beta.1",
"private": true,
"description": "Official documentation for the VeChain TypeScript SDK with examples",
"author": "VeChain Foundation",
Expand All @@ -17,8 +17,8 @@
"test:examples:solo": "(yarn start-thor-solo && yarn test:examples && yarn stop-thor-solo) || yarn stop-thor-solo"
},
"dependencies": {
"@vechain/sdk-core": "1.0.0-rc.5",
"@vechain/sdk-network": "1.0.0-rc.5"
"@vechain/sdk-core": "2.0.0-beta.1",
"@vechain/sdk-network": "2.0.0-beta.1"
},
"devDependencies": {
"expect": "^29.7.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"devDependencies": {
"@changesets/cli": "^2.27.7",
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.1.0",
"@eslint/eslintrc": "^3.1.0",
"@commitlint/config-conventional": "^19.6.0",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.17.0",
"@jest/globals": "^29.7.0",
"@types/fs-extra": "^11.0.4",
Expand Down
10 changes: 5 additions & 5 deletions packages/aws-kms-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vechain/sdk-aws-kms-adapter",
"version": "1.0.0-rc.5",
"version": "2.0.0-beta.1",
"description": "This module implements the VeChain abstract signer so it is integrated with AWS KMS",
"author": "VeChain Foundation",
"license": "MIT",
Expand Down Expand Up @@ -40,11 +40,11 @@
"dependencies": {
"@aws-sdk/client-kms": "^3.723.0",
"@noble/curves": "^1.7.0",
"@vechain/sdk-core": "1.0.0-rc.5",
"@vechain/sdk-errors": "1.0.0-rc.5",
"@vechain/sdk-network": "1.0.0-rc.5",
"@vechain/sdk-core": "2.0.0-beta.1",
"@vechain/sdk-errors": "2.0.0-beta.1",
"@vechain/sdk-network": "2.0.0-beta.1",
"asn1js": "^3.0.5",
"ethers": "6.13.4",
"ethers": "6.13.5",
"viem": "^2.21.54"
}
}
76 changes: 6 additions & 70 deletions packages/aws-kms-adapter/src/KMSVeChainSigner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bytesToHex, concatBytes } from '@noble/curves/abstract/utils';
import { type SignatureType } from '@noble/curves/abstract/weierstrass';
import { secp256k1 } from '@noble/curves/secp256k1';
import { Address, Hex, Keccak256, Transaction, Txt } from '@vechain/sdk-core';
import { Address, Hex, Transaction } from '@vechain/sdk-core';
import { JSONRPCInvalidParams, SignerMethodError } from '@vechain/sdk-errors';
import {
type AvailableVeChainProviders,
Expand All @@ -11,13 +11,7 @@ import {
VeChainAbstractSigner
} from '@vechain/sdk-network';
import { BitString, ObjectIdentifier, Sequence, verifySchema } from 'asn1js';
import {
hashTypedData,
recoverPublicKey,
toHex,
type TypedDataDomain,
type TypedDataParameter
} from 'viem';
import { recoverPublicKey, toHex } from 'viem';
import { KMSVeChainProvider } from './KMSVeChainProvider';

class KMSVeChainSigner extends VeChainAbstractSigner {
Expand Down Expand Up @@ -157,7 +151,7 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
}

/**
* It builds a VeChain signature from a bytes payload.
* It builds a VeChain signature from a bytes' payload.
* @param {Uint8Array} payload to sign.
* @param {KMSVeChainProvider} kmsProvider The provider to sign the payload.
* @returns {Uint8Array} The signature following the VeChain format.
Expand Down Expand Up @@ -188,12 +182,10 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
kmsProvider
);

const decodedSignature = concatBytes(
return concatBytes(
decodedSignatureWithoutRecoveryBit.toCompactRawBytes(),
new Uint8Array([recoveryBit])
);

return decodedSignature;
}

/**
Expand Down Expand Up @@ -314,7 +306,7 @@ class KMSVeChainSigner extends VeChainAbstractSigner {

/**
* Submits a signed transaction to the network.
* @param transactionToSend Transaction to by signed and sent to the network.
* @param transactionToSend Transaction to be signed and sent to the network.
* @returns {string} The transaction ID.
*/
public async sendTransaction(
Expand Down Expand Up @@ -345,69 +337,13 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
* @param {Uint8Array} payload in bytes to sign.
* @returns {string} The VeChain signature in hexadecimal format.
*/
private async signPayload(payload: Uint8Array): Promise<string> {
public async signPayload(payload: Uint8Array): Promise<string> {
const veChainSignature =
await this.buildVeChainSignatureFromPayload(payload);
// SCP256K1 encodes the recovery flag in the last byte. EIP-191 adds 27 to it.
veChainSignature[veChainSignature.length - 1] += 27;
return Hex.of(veChainSignature).toString();
}

/**
* Signs a message returning the VeChain signature in hexadecimal format.
* @param {string | Uint8Array} message to sign.
* @returns {string} The VeChain signature in hexadecimal format.
*/
public async signMessage(message: string | Uint8Array): Promise<string> {
try {
const payload =
typeof message === 'string' ? Txt.of(message).bytes : message;
const payloadHashed = Keccak256.of(
concatBytes(
this.MESSAGE_PREFIX,
Txt.of(payload.length).bytes,
payload
)
).bytes;
return await this.signPayload(payloadHashed);
} catch (error) {
throw new SignerMethodError(
'KMSVeChainSigner.signMessage',
'The message could not be signed.',
{ message },
error
);
}
}

/**
* Signs a typed data returning the VeChain signature in hexadecimal format.
* @param {TypedDataDomain} domain to hash as typed data.
* @param {Record<string, TypedDataField[]>} types to hash as typed data.
* @param {Record<string, unknown>} value to hash as typed data.
* @returns {string} The VeChain signature in hexadecimal format.
*/
public async signTypedData(
domain: TypedDataDomain,
types: Record<string, TypedDataParameter[]>,
primaryType: string,
message: Record<string, unknown>
): Promise<string> {
try {
const payload = Hex.of(
hashTypedData({ domain, types, primaryType, message })
).bytes;

return await this.signPayload(payload);
} catch (error) {
throw new SignerMethodError(
'KMSVeChainSigner.signTypedData',
'The typed data could not be signed.',
{ domain, types, primaryType, message },
error
);
}
}
}

export { KMSVeChainSigner };
21 changes: 18 additions & 3 deletions packages/aws-kms-adapter/tests/KMSVeChainSigner.solo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,27 @@ describe('KMSVeChainSigner - Thor Solo', () => {
const signature = await signer.signTypedData(
typedData.domain,
typedData.types,
typedData.primaryType,
typedData.data
typedData.data,
typedData.primaryType
);
expect(signature).toBeDefined();
// 64-bytes hex string
expect(signature.length).toBe(132);
expect(signature).toMatch(/^0x[A-Fa-f0-9]{130}$/);

const signatureWithoutPrimaryType = await signer.signTypedData(
typedData.domain,
typedData.types,
typedData.data
);
expect(signatureWithoutPrimaryType).toBeDefined();
// 64-bytes hex string
expect(signatureWithoutPrimaryType).toMatch(/^0x[A-Fa-f0-9]{130}$/);

// Not checking directly the signatures since there is an issue in LocalStack:
// https://github.com/localstack/localstack/issues/11678
// Looks like, regardless the configuration, a new SECP256r1 key is generated
// meaning that the signature will be different every time.
// However both hashes have been checked and they match, + tests in the other implementation.
});
});
});
Loading

0 comments on commit 168786c

Please sign in to comment.