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

fcl-azurevault-authorizer

v0.2.3

Published

Azure Vault authorizer (signer) for Flow blockchain.

Downloads

91

Readme

fcl-azurevault-authorizer

Azure Vault authorizer (signer) for Flow blockchain.

Installation

npm i fcl-azurevault-authorizer

Usage


import * as fcl from '@onflow/fcl';
import { AzureVaultAuthorizer } from 'fcl-azurevault-authorizer';
import { DefaultAzureCredential, ClientSecretCredential } from '@azure/identity';

// Key configuration. Store it in env variables or secret manager
const keyId = "https://<vault-name>.vault.azure.net/keys/<key-name>/xxxxxxxxxxxxxxxx";
const keyVaultUrl = 'https://<vault-name>.vault.azure.net';
const keyName = '<key-name>';


// Test transaction
const transaction = `
transaction {
  prepare(signer: AuthAccount) {
    log("Test transaction signed by fcl-azurevault-authorizer")
  }
}
`;

async function main() {

  const credential = new DefaultAzureCredential();

  // Use ClientSecretCredential if don't want to use DefaultAzureCredential

  // const credential = new ClientSecretCredential(
  //   <tenant-id>,
  //   <client-id>,
  //   <client-secret>
  // );

  // Create an instance of the authorizer
  const authorizer = new AzureVaultAuthorizer(
    credential, keyId, keyName, keyVaultUrl
  );

  // address created using public key 
  const address = '01cf0e2f2f715450';
  const keyIndex = 0;

  // Sign and send transactions with Azure Vault
  const authorization = authorizer.authorize(address, keyIndex);

  const response = await fcl.send([
    fcl.transaction`${transaction}`,
    fcl.args([]),
    fcl.proposer(authorization),
    fcl.authorizations([authorization]),
    fcl.payer(authorization),
    fcl.limit(9999),
  ]);
  await fcl.tx(response).onceSealed();

  console.log('Transaction Succeeded');
}

main().catch(e => console.error(e));

see sign-tx.ts in examples folder for complete example.

Azure Vault setup

Note: In order to use fcl-azurevault-authorizer for remote key management, you'll need a Azure Platform account.

  • Open the Azure portal. Select Key Vaults.
  • Create a new key vault.
  • Select Settings>Keys>Generate
  • Select key type -> EC.
  • Select Elliptic curve name -> P-256.
  • create the key. After creation, select the created key to get more info.
  • Copy the Key Identifier, it will be used as keyId while initializing AzureVaultAuthorizer.

To be able to use it from backend code, use the following steps -

  1. first install azure-cli, az. You can find detailed steps here.

  2. login to authenticate your account using az login.

  3. Create a service principal to enable access to key vault resource -

az ad sp create-for-rbac -n <your-application-name> --skip-assignment

Output :

{
  "appId": "generated-app-ID",
  "displayName": "dummy-app-name",
  "name": "http://dummy-app-name",
  "password": "random-password",
  "tenant": "tenant-ID"
}
  1. Use the above returned credentials information to set AZURE_CLIENT_ID(appId), AZURE_CLIENT_SECRET(password) and AZURE_TENANT_ID(tenant) environment variables. The following example shows a way to do this in Bash:
  export AZURE_CLIENT_ID="generated-app-ID"
  export AZURE_CLIENT_SECRET="random-password"
  export AZURE_TENANT_ID="tenant-ID"
  1. Grant the above mentioned application authorization to perform key operations on the keyvault:
az keyvault set-policy --name <your-key-vault-name> --spn $AZURE_CLIENT_ID --key-permissions backup create get import list sign verify
  1. To verify the setup, use the above mentioned Key Vault name to retrieve details of your Vault which also contains your Key Vault URL:
az keyvault show --name <your-key-vault-name>

Creating an account on testnet via the faucet:

  1. Get the public key using authorizer.getPublicKey()
  2. Go to https://testnet-faucet-v2.onflow.org
  3. Paste the copied public key in the form
  4. IMPORTANT: Choose SHA2_256 as the hash algorithm (SHA3_256 won't work with the key setup above)

Store the generated address and use it while creating the authorization -

const authorization = authorizer.authorize(accountAddress, keyIndex);

Credits

This fcl compatible Azure Vault authorizer is built taking inspiration from fcl-kms-authorizer