npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vechain/sdk-aws-kms-adapter

v1.0.0-rc.3

Published

This module implements the VeChain abstract signer so it is integrated with AWS KMS

Downloads

187

Readme

AWS KMS Adapter for VeChain SDK

The AWS KMS Adapter for VeChain SDK provides a secure way to sign transactions using AWS Key Management Service (KMS). This adapter allows you to leverage AWS KMS to manage and protect your private keys, ensuring that sensitive cryptographic operations are performed in a secure environment.

Features

  • Secure Key Management: Use AWS KMS to securely manage and protect your private keys.
  • Transaction Signing: Sign VeChain transactions using keys stored in AWS KMS.
  • Integration with VeChain SDK: Seamlessly integrate with the VeChain SDK for blockchain interactions.
  • Sign and send transactions using a delegator key: You can specify the key ID of a delegator key to leverage this VeChain feature for signing and sending transactions.

Installation

To install the AWS KMS Adapter, use the following command:

yarn add @vechain/sdk-aws-kms-adapter

Test

To run all the tests, including the ones relying on a local instance of Thor Solo + LocalStack and Testnet, please run:

yarn test:integration

Usage

To integrate this into your code, depending on how you plan to manage your AWS credentials, you can choose one of the following examples.

Within this repo, you can create a credentials file called aws-credentials.json with your custom credentials under the tests folder in case you want to give it a try before integrating with your project. A valid format would be as follows (it is an array in case you want to include a delegator key, assumed to be the second one):

[
    {
        // AWS KMS keyId (mandatory)
        "keyId": "00000000-0000-0000-0000-000000000000", 
        // AWS region (mandatory)
        "region": "eu-west-1",
        // AWS credentials (optional)
        "credentials": { 
            // AWS access key id (mandatory if credentials)
            "accessKeyId": "test",
            // AWS secret access key (mandatory if credentials)
            "secretAccessKey": "test",
            // AWS session token if SSO is configured (optional)
            "sessionToken": "test"
        },
        // AWS endpoint (optional, to be used locally along with LocalStack)
        "endpoint": "http://localhost:4599"
    }
]

IAM roles

This is the preferred way. If you integrate this library in an app deployed in AWS following with IAM roles, you can just do as follows:

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'
    };
    ...

    const thorClient = ThorClient.fromUrl(THOR_SOLO_URL);
    const provider = new KMSVeChainProvider(
        thorClient,
        awsClientParameters
    );
    const signer = new KMSVeChainSigner(provider);
    // Signing typed data as per EIP712
    const signature = await signer.signTypedData(
                typedData.domain,
                typedData.types,
                typedData.data
            );

AWS credentials (SSO)

This way you can connect to your AWS account by using accessKeyId, secretAccessKey and sessionToken if SSO is enabled.

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

    const thorClient = ThorClient.fromUrl(THOR_SOLO_URL);
    const provider = new KMSVeChainProvider(
        thorClient,
        awsClientParameters
    );
    const signer = new KMSVeChainSigner(provider);
    // Signing and sending a transaction
    const receipt = await signer.sendTransaction(
                signerUtils.transactionBodyToTransactionRequestInput(
                    txBody,
                    originAddress
                )
            );

AWS endpoint (LocalStack)

You can also leverage LocalStack so you can try the library locally. Sample values are included in the file tests/test-aws-credentials.json.

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 thorClient = ThorClient.fromUrl(THOR_SOLO_URL);
    const provider = new KMSVeChainProvider(
        thorClient,
        awsClientParameters
    );
    const signer = new KMSVeChainSigner(provider);
    // Returns the address related to the KMS key
    const address = await signer.getAddress();

Delegation (provider)

You can also use delegation to sign your transactions. In this example the source of the delegation is a delegator which key is in KMS so requires a KMSVeChainProvider.

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 thorClient = ThorClient.fromUrl(THOR_SOLO_URL);
    const provider = new KMSVeChainProvider(
        thorClient,
        awsClientParameters
    );

    // Signer with delegator 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 delegator KMS key
    const address = await signerWithDelegator.getAddress(true);

Delegation (url)

You can also use delegation to sign your transactions. In this example the source of the delegation is a URL that returns the signature (for instance, https://sponsor-testnet.vechain.energy/by/705, more details on how to get yours here).

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 thorClient = ThorClient.fromUrl(THOR_SOLO_URL);

    // Signer with delegator enabled
    const provider = new KMSVeChainProvider(
        thorClient,
        awsClientParameters
    );
    const signerWithDelegator = 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();

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