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

emblem-vault-sdk

v2.3.0

Published

Emblem Vault Software Development Kit

Downloads

278

Readme

Emblem Vault SDK Documentation

The Emblem Vault SDK is a JavaScript library that provides functionality for interacting with Emblem Vaults, including creating vaults, refreshing balances, and performing minting operations.

Table of Contents

Installation

To use the Emblem Vault SDK in your project, include the bundle.js file in your HTML file:

<script src="./bundle.js"></script>

Or use within NodeJS by npm install emblem-vault-sdk

let EmblemVaultSDK = require('emblem-vault-sdk').default

Initialization

To initialize the SDK, create an instance of the EmblemVaultSDK class:


const sdk = new EmblemVaultSDK('demo');

Fetching Curated Contracts

To fetch the curated contracts, use the fetchCuratedContracts method:

sdk.fetchCuratedContracts(false).then(curatedContracts => {
    // Use the curated contracts
});

Creating a Vault

To create a vault, prepare a contract template object and call the createCuratedVault method:

let contractTemplate = {
    fromAddress: null,
    toAddress: null,
    chainId: 1,
    experimental: true,
    targetContract: {
        "1": "0x345eF9d7E75aEEb979053AA41BB6330683353B7b",
        "5": "0x582699d2c58A38056Cf02875540705137f0bbbF7",
        name: "Bitcoin DeGods",
        description: "Bitcoin DeGods is a collection of 535 Bitcoin Ordinals inscribed in the 77236 to 77770 range. This collection is curated by Emblem Vault."
    },
    targetAsset: {
        image: "https://emblem.finance/btcdegods.jpg",
        name: "Loading...",
        xtra: "anything else you need here"
    }
};

vaultData = await sdk.createCuratedVault(contractTemplate, updateLogCallback);

Refreshing Vault Balance

To refresh the balance of a vault, use the refreshBalance method:

vaultBalance = await sdk.refreshBalance(vaultData.tokenId, updateLogCallback);

Validating Mintability

To validate if a vault is mintable, use the allowed method of the curated contract object:

let contractObject = await sdk.fetchCuratedContractByName(contractTemplate.targetContract.name);
let mintable = contractObject.allowed(vaultBalance, contractObject);

Performing a Mint

To perform a mint, use the performMintChain method:

sdk.performMintChain(web3, vaultData.tokenId, contractTemplate.targetContract.name, updateLogCallback)
    .then(result => {
        // Handle success
    })
    .catch(error => {
        // Handle error
    });

Utility Functions

generateUploadUrl()

Generates a URL for uploading files.

generateAttributeTemplate(record: any)

Generates an attribute template based on the provided record.

  • Parameters:
    • record: The record object containing information about the asset.
  • Returns:
    • An array of attribute templates.

generateImageTemplate(record: any)

Generates an image template based on the provided record.

  • Parameters:
    • record: The record object containing information about the asset.
  • Returns:
    • An object containing image template properties.

generateTemplate(record: any)

Generates a template for a given curated collection record.

  • Parameters:
    • record: The curated collection record.
  • Returns: A template object containing rules and utilities for the curated collection.

templateGuard(input: { [x: string]: any; hasOwnProperty: (arg0: string) => any; })

Validates the provided template input and throws an error if any required fields are missing or invalid.

  • Parameters:
    • input: The template input object to validate.

genericGuard(input: any, type: string, key: string)

Validates the provided input against the specified type and key.

  • Parameters:
    • input: The input value to validate.
    • type: The expected type of the input.
    • key: The key or name of the input.

getQuoteContractObject(web3: any)

Retrieves the quote contract object using the provided Web3 instance. Used to calculate the amount in BASE CURRENCY to charge for an operation

  • Parameters:
    • web3: The Web3 instance.
  • Returns:
    • A promise that resolves to the quote contract object.

Example

    let USDPrice = 25;
    ...
        const quoteContract = await sdk.getQuoteContractObject(web3);
    ...
        // Get the current user's account    
        const userAccount = accounts[0];

        // Call the quoteExternalPrice method on the quote contract
        const quote = await quoteContract.methods.quoteExternalPrice(userAccount, USDPrice).call();

        console.log('Quote:', quote);
    } catch (error) {
        console.error('Error getting quote:', error);
    }

getHandlerContract(web3: any)

Retrieves the handler contract object using the provided Web3 instance.

  • Parameters:
    • web3: The Web3 instance.
  • Returns:
    • A promise that resolves to the handler contract object.

getLegacyContract(web3: any)

Retrieves the legacy contract object using the provided Web3 instance.

  • Parameters:
    • web3: The Web3 instance.
  • Returns:
    • A promise that resolves to the legacy contract object.

checkContentType(url: string)

Checks the content type of the provided URL by making a HEAD request.

  • Parameters:
    • url: The URL to check the content type of.
  • Returns:
    • A promise that resolves to an object containing the content type information.

getTorusKeys(verifierId: string, idToken: any, cb: any = null)

Retrieves the Torus keys using the provided verifier ID and ID token.

  • Parameters:
    • verifierId: The verifier ID.
    • idToken: The ID token.
    • cb (optional): A callback function to handle the retrieved keys.
  • Returns:
    • A promise that resolves to an object containing the private key.

decryptKeys(vaultCiphertextV2: any, keys: any, addresses: any[])

Decrypts the vault keys using the provided ciphertext, keys, and addresses.

  • Parameters:
    • vaultCiphertextV2: The vault ciphertext to decrypt.
    • keys: The keys used for decryption.
    • addresses: An array of addresses associated with the vault.
  • Returns:
    • A promise that resolves to the decrypted payload.

getSatsConnectAddress()

Retrieves the Sats Connect address.

  • Returns:
    • A promise that resolves to an object containing the payment address, payment public key, and ordinals address.

signPSBT(psbtBase64: any, paymentAddress: any, indexes: number[], broadcast: boolean = false)

Signs a Partially Signed Bitcoin Transaction (PSBT) using the provided PSBT base64 data, payment address, and input indexes.

  • Parameters:
    • psbtBase64: The base64-encoded PSBT data.
    • paymentAddress: The payment address.
    • indexes: An array of input indexes to sign.
    • broadcast (optional): A boolean indicating whether to broadcast the transaction after signing (default: false).
  • Returns:
    • A promise that resolves to the signed PSBT response.

Example Usage

Here's an example of how to use the Emblem Vault SDK to create a vault, refresh its balance, validate mintability, and perform a mint:

async function Step1() {
    if (!defaultAccount) {
        await sdk.loadWeb3();
        defaultAccount = await web3.eth.getAccounts().then(accounts => accounts[0]).catch(err => console);
    }
    if (!vaultData) {
        let chainId = Number(await web3.eth.net.getId());
        contractTemplate.toAddress = defaultAccount;
        contractTemplate.fromAddress = defaultAccount;
        contractTemplate.chainId = chainId;
        vaultData = await sdk.createCuratedVault(contractTemplate, updateLogCallback).catch(err => console.log(err));
        if (!vaultData || vaultData.err) {
            setTimeout(Step1, 1000);
        } else {
            updateLogCallback("deposit Address", vaultData.addresses.find(address => { return address.coin == 'TAP' }).address);
        }
    }
}

async function Step2() {
    if (vaultData) {
        vaultBalance = await sdk.refreshBalance(vaultData.tokenId, updateLogCallback).catch(err => console);
    }
}

async function Step3() {
    if (vaultBalance.length > 0) {
        let contractObject = await sdk.fetchCuratedContractByName(contractTemplate.targetContract.name);
        let mintable = contractObject.allowed(vaultBalance, contractObject);
        if (mintable) {
            performMint();
        }
    }
}

async function performMint() {
    if (vaultData.tokenId) {
        sdk.performMintChain(web3, vaultData.tokenId, contractTemplate.targetContract.name, updateLogCallback)
            .then(result => {
                updateLogCallback('Minting success', 'tokenId: ' + vaultData.tokenId);
            })
            .catch(error => {
                updateLogCallback('', error.message);
            });
    }
}

This example demonstrates the step-by-step process of creating a vault, refreshing its balance, validating mintability, and performing a mint using the Emblem Vault SDK.